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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user