puppet-prod/site/profiles/manifests/firstrun/packages.pp
Ben Vincent cc01259a64 feat: change packages to Hash
- change from multiple arrays for managing packages to a hash
- change to ensure_packages to prevent duplicate resource conflicts
2024-07-27 13:01:06 +10:00

35 lines
1023 B
Puppet

# profiles::firstrun::packages
class profiles::firstrun::packages (
Hash $manage = lookup('profiles::packages::include'),
) {
# include the correct package repositories, define the install_packages exec
case $facts['os']['family'] {
'RedHat': {
include profiles::yum::global
$install_command = 'dnf install -y'
}
'Debian': {
include profiles::apt::global
$install_command = 'apt-get install -y'
}
default: {
fail("Unsupported OS family ${facts['os']['family']}")
}
}
# filter out packages with 'ensure' set to 'absent'
$packages_to_install = $manage.filter |$package, $options| {
!($options['ensure'] and $options['ensure'] == 'absent')
}
# get all the packages to install, and convert into a space separated list
$packages = $packages_to_install.keys
$package_list = $packages.join(' ')
# install all the packages
exec { 'install_packages':
command => "${install_command} ${package_list}",
path => ['/bin', '/usr/bin'],
}
}