feat: change packages to Hash

- change from multiple arrays for managing packages to a hash
- change to ensure_packages to prevent duplicate resource conflicts
This commit is contained in:
2024-07-27 04:09:59 +10:00
parent 01fc6aacd7
commit cc01259a64
10 changed files with 115 additions and 106 deletions
+9 -2
View File
@@ -1,5 +1,7 @@
# profiles::firstrun::packages
class 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': {
@@ -15,8 +17,13 @@ class profiles::firstrun::packages {
}
}
# 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 = hiera_array('profiles::packages::install', [])
$packages = $packages_to_install.keys
$package_list = $packages.join(' ')
# install all the packages
+10 -14
View File
@@ -1,23 +1,19 @@
# This class manages the installation of packages for the base profile
#
# Parameters:
# - $install: An array of package names to be installed
# - $remove: An array of package names to be removed
# - $include: A hash of package names to be managed
# - $exclude: An array of package names to be removed from managed hash
#
class profiles::packages (
Array $install = [],
Array $install_exclude = [],
Array $remove = [],
Array $remove_exclude = [],
Hash $include = {},
Array[String] $exclude = [],
) {
# Filter out excluded packages
$install_real = $install.filter |$item| { !$install_exclude.any |$exclude_item| { $exclude_item == $item } }
$remove_real = $remove.filter |$item| { !$remove_exclude.any |$exclude_item| { $exclude_item == $item } }
# Filter the include hash to remove the packages listed in exclude
$filtered_include = filter($include) |$key, $value| {
!($key in $exclude)
}
# Ensure packages to install are installed
ensure_packages($install_real, {'ensure' => 'present'})
# Ensure packages to remove are absent
ensure_packages($remove_real, {'ensure' => 'absent'})
# Manage packages
ensure_packages($filtered_include)
}