简体   繁体   中英

Use command output in puppet ensure_packages package definition

I am currently installing kernel headers from a puppet manifest with the following:

    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.

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. You would accomplish that with the help of the 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. If not, then it should be pretty easy to write a custom fact for this purpose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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