Search code examples
puppetamazon-linux-2

How do I install package from amazon-linux-extras using Puppet?


I am trying to set up a Puppet module to install PHP 7.3 on Amazon Linux 2. It is available as a amazon-linux-extras package.

I could simply install it using CLI:

amazon-linux-extras install php7.3

But I would like to define it as a package and ensure it is installed, like this:

package { "php7.3":
  ensure => installed,
  provider => 'amazon-linux-extras'
}

Unfortunately I cannot set package provider to amazon-linux-extras as such provider doesn't exist.

What would be the correct way to install this package?


Solution

  • At this time, it appears that Puppet does not support the amazon-linux-extras utility.

    Arguably, a new type/provider should be created to support amazon-linux-extras. It could live in Puppet Core, if you raised a feature request that is accepted. Or, you could write your own and release it as a module on the Puppet Forge, if you know how write custom types and providers.

    In the mean time, it is easy to write a defined type to solve this problem using exec.

    define al::amazon_linux_extras(
      Enum['present'] $ensure = present,
      ) {
      $pkg = $name
      exec { "amazon-linux-extras install -y $pkg":                                                                                                                        
        unless => "amazon-linux-extras list | grep -q '${pkg}=.*enabled'",                                                                                                 
        path   => '/usr/bin',                                                                                                                                              
      }                                                                                                                                                                    
    }                                                                                                                                                                      
    

    Usage:

    al::amazon_linux_extras { 'php7.3':
      ensure => present,
    }
    

    Further explanation:

    • I assumed you would place your defined type in a module al. But it could be a profile etc. E.g. profile::amazon_linux_extras is another possibility.
    • I implemented ensure => present for readability only, i.e. it doesn't actually do anything, and also in case you decide to later implement ensure => absent or ensure => latest etc.