简体   繁体   English

在 puppet ensure_packages package 定义中使用命令 output

[英]Use command output in puppet ensure_packages package definition

I am currently installing kernel headers from a puppet manifest with the following:我目前正在从木偶清单安装 kernel 标头,其中包含以下内容:

    ensure_packages([
    'linux-headers-4.19.0-12-cloud-amd64',
    ],
  { 'ensure'   => 'present' })

It would make more sense if I could use the uname -r command rather than hardcoding the kernel version, so that the kernel version instance where it is being installed is retrieved automatically.如果我可以使用uname -r命令而不是硬编码 kernel 版本会更有意义,以便自动检索正在安装它的 kernel 版本实例。

So I've tried configuring this with the following.因此,我尝试使用以下内容进行配置。

    ensure_packages([
    "linux-headers-$(uname -r)",
    ],
  { 'ensure'   => 'present' })

But this is failing as it doesn't seem to resolve the command.但这失败了,因为它似乎无法解决该命令。

Is this even possible in puppet?这在傀儡中甚至可能吗?

Is this even possible in puppet?这在傀儡中甚至可能吗?

Yes, it is possible to run an external command during catalog building, capture the output, and use that like any other string to inform the details of the catalog.是的,可以在目录构建期间运行外部命令,捕获 output,并像使用任何其他字符串一样使用它来通知目录的详细信息。 You would accomplish that with the help of the generate() function .您将generate() function的帮助下完成此操作。 You might need to specify an explicit path to the command.您可能需要指定命令的显式路径。

But that's not what you actually want.但这不是你真正想要的。

If you perform the evaluation during catalog building then you will get data pertaining to the machine on which the catalog is built, which is usually a different machine from the one to which the catalog will be applied.如果您在目录构建期间执行评估,那么您将获得与构建目录的机器相关的数据,该机器通常与应用目录的机器不同。 The most appropriate vehicle for conveying target machine details to the catalog builder is facts .向目录生成器传达目标机器详细信息的最合适的工具是事实 You would want to check whether the core (built-in) kernel fact already provides what you want.您需要检查核心(内置) kernel事实是否已经提供了您想要的。 If not, then it should be pretty easy to write a custom fact for this purpose.如果没有,那么为此目的编写自定义事实应该很容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM