diff --git a/README.md b/README.md index 41a2d9f7..eb449add 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,11 @@ class { 'yum': gpgcheck => false|true, installonly_limit => number, keep_kernel_devel => false|true, + clean_old_kernels => false|true, } ``` -If `installonly_limit` is changed, purging of old kernel packages is triggered. +If `installonly_limit` is changed, purging of old kernel packages is triggered if `clean_old_kernels` is `true`. ### yum::config diff --git a/manifests/init.pp b/manifests/init.pp index 970a501c..83f2ebe0 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -28,11 +28,12 @@ $obsoletes = $yum::params::obsoletes, $gpgcheck = $yum::params::gpgcheck, $installonly_limit = $yum::params::installonly_limit, - $keep_kernel_devel = $yum::params::keep_kernel_devel + $keep_kernel_devel = $yum::params::keep_kernel_devel, + $clean_old_kernels = $yum::params::clean_old_kernels ) inherits yum::params { validate_bool($keepcache, $exactarch, $obsoletes, $gpgcheck) - validate_bool($keep_kernel_devel) + validate_bool($keep_kernel_devel, $clean_old_kernels) unless is_integer($installonly_limit) { validate_string($installonly_limit) @@ -42,6 +43,12 @@ validate_string($debuglevel) } + if $clean_old_kernels { + $_installonly_limit_notify = Exec['package-cleanup_oldkernels'] + } else { + $_installonly_limit_notify = undef + } + # configure Yum yum::config { 'keepcache': ensure => bool2num($keepcache), @@ -65,7 +72,7 @@ yum::config { 'installonly_limit': ensure => $installonly_limit, - notify => Exec['package-cleanup_oldkernels'], + notify => $_installonly_limit_notify, } # cleanup old kernels diff --git a/manifests/params.pp b/manifests/params.pp index 262824ad..ffc1529f 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -8,6 +8,7 @@ $gpgcheck = true $installonly_limit = 5 $keep_kernel_devel = false + $clean_old_kernels = true } default: { fail("${::operatingsystem} not supported") diff --git a/spec/classes/basic_spec.rb b/spec/classes/basic_spec.rb index 7068fd27..cf0ca607 100644 --- a/spec/classes/basic_spec.rb +++ b/spec/classes/basic_spec.rb @@ -12,6 +12,18 @@ it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('yum::params') } + + it do + is_expected.to contain_yum__config('installonly_limit').with( + ensure: '5', + notify: 'Exec[package-cleanup_oldkernels]' + ) + end + end + + context 'clean_old_kernels => false' do + let(:params) { { clean_old_kernels: false } } + it { is_expected.to contain_yum__config('installonly_limit').without_notify } end end end