# Class: profiles::yum::global # # This class manages global YUM configurations and optionally includes the # base and EPEL yum repository profiles based on the content of the # $managed_repos parameter, which is an array of repository names. # # Parameters: # ----------- # - $managed_repos: An array of repository names that the Puppet agent should # manage. This parameter is mandatory and the class will # fail if it is not provided via hieradata. # Example: ['base', 'updates', 'extras', 'appstream'] # # Actions: # -------- # - Configures global YUM settings, including keeping the kernel development # packages and cleaning old kernels. # # - Establishes default parameters for any YUM repositories managed by Puppet. # This includes the repository file location, the repository description, # and enabling the repository and GPG checks. # # - Depending on the content of the $managed_repos parameter, it includes the # profiles::yum::base and/or profiles::yum::epel classes. # # - Manages all .repo files under /etc/yum.repos.d. All the repositories listed # in $managed_repos will have their corresponding .repo files preserved. Any # .repo file that is not listed in $managed_repos will be removed. # # - Creates and maintains a /etc/yum.repos.d/.managed file that lists all the # .repo files that should be managed by Puppet. # # Example usage: # -------------- # To use this class, include the class and configure hieradata: # include profiles::yum::global # # profiles::yum::managed_repos: # - 'base' # - 'extras' # - 'appstream' # class profiles::yum::global ( Array[String] $managed_repos = lookup('profiles::yum::managed_repos'), ){ class { 'yum': keep_kernel_devel => true, clean_old_kernels => true, config_options => { gpgcheck => true, }, } Yumrepo { ensure => 'present', enabled => 1, gpgcheck => 1, mirrorlist => 'absent', } # tidy { '/etc/yum.repos.d': # matches => ['*.repo', '!*.managed.repo'], # recurse => true, # rmdirs => false, # age => '0s', # backup => false, # type => 'ctime', # } # Generate the content for the .managed file $managed_file_content = $managed_repos.map |$repo_name| { "${repo_name}.repo" }.join("\n") # Create the .managed file file { '/etc/yum.repos.d/.managed': ensure => file, content => $managed_file_content, } # Define exec resource to remove .repo files not listed in .managed exec { 'cleanup_yum_repos': command => '/bin/bash -c "comm -23 <(ls /etc/yum.repos.d | sort) <(sort /etc/yum.repos.d/.managed) | xargs -n1 rm -f /etc/yum.repos.d/{}"', onlyif => '/bin/bash -c "comm -23 <(ls /etc/yum.repos.d | sort) <(sort /etc/yum.repos.d/.managed) | grep .repo"', } # Setup base repos class { 'profiles::yum::base': managed_repos => $managed_repos, } # Setup epel if included in managed_repos class { 'profiles::yum::epel': managed_repos => $managed_repos, } # Setup puppet7 if included in managed_repos class { 'profiles::yum::puppet7': managed_repos => $managed_repos, } }