diff --git a/manifests/agent/service/cron.pp b/manifests/agent/service/cron.pp index da52315d..a6677815 100644 --- a/manifests/agent/service/cron.pp +++ b/manifests/agent/service/cron.pp @@ -8,6 +8,7 @@ unless $puppet::runmode == 'unmanaged' or 'cron' in $puppet::unavailable_runmodes { if $enabled { $command = pick($puppet::cron_cmd, "${puppet::puppet_cmd} agent --config ${puppet::dir}/puppet.conf --onetime --no-daemonize") + $target = $puppet::cron_target $times = extlib::ip_to_cron($puppet::runinterval) $_hour = pick($hour, $times[0]) @@ -18,6 +19,7 @@ user => root, hour => $_hour, minute => $_minute, + target => $target, } } else{ cron { 'puppet': diff --git a/manifests/init.pp b/manifests/init.pp index 5352f0df..8e07dd25 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -75,6 +75,9 @@ # $cron_cmd:: Specify command to launch when runmode is # set 'cron'. # +# $cron_target:: Specify the target crontab file when runmode is +# set 'cron'. +# # $systemd_cmd:: Specify command to launch when runmode is # set 'systemd.timer'. # @@ -597,6 +600,7 @@ Variant[Integer[0,59], Array[Integer[0,59]], Undef] $run_minute = undef, Array[Enum['cron', 'service', 'systemd.timer', 'none']] $unavailable_runmodes = $puppet::params::unavailable_runmodes, Optional[String] $cron_cmd = $puppet::params::cron_cmd, + Optional[String] $cron_target = $puppet::params::cron_target, Optional[String] $systemd_cmd = $puppet::params::systemd_cmd, Integer[0] $systemd_randomizeddelaysec = $puppet::params::systemd_randomizeddelaysec, Boolean $agent_noop = $puppet::params::agent_noop, diff --git a/manifests/params.pp b/manifests/params.pp index 4eab6d50..8924acee 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -17,6 +17,7 @@ # Not defined here as the commands depend on module parameter "dir" $cron_cmd = undef + $cron_target = undef $systemd_cmd = undef $agent_noop = false diff --git a/manifests/server/config.pp b/manifests/server/config.pp index 26f4640c..13ac3b03 100644 --- a/manifests/server/config.pp +++ b/manifests/server/config.pp @@ -185,7 +185,7 @@ owner => $puppet::server::user, group => $puppet::server::group, mode => '0644', - content => file($::settings::cacrl, $::settings::hostcrl, '/dev/null'), + content => file($settings::cacrl, $settings::hostcrl, '/dev/null'), } } } diff --git a/spec/classes/puppet_agent_spec.rb b/spec/classes/puppet_agent_spec.rb index 35231e9c..dfed8c56 100644 --- a/spec/classes/puppet_agent_spec.rb +++ b/spec/classes/puppet_agent_spec.rb @@ -254,6 +254,54 @@ end end + describe 'when runmode => cron with specified target' do + let :params do + super().merge(runmode: 'cron', + cron_target: '/etc/cron.d/puppet' + ) + end + + case os + when /\A(windows|archlinux)/ + it { is_expected.to raise_error(Puppet::Error, /Runmode of cron not supported on #{facts[:kernel]} operating systems!/) } + when /\Adebian-/, /\A(redhat|centos|scientific)-(7|8)/, /\Afedora-/, /\Aubuntu-/, /\Asles-12/ + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat__fragment('puppet.conf_agent') } + it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(true) } + it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(false) } + it do + is_expected.to contain_service('puppet') + .with_ensure('stopped') + .with_name('puppet') + .with_hasstatus('true') + .with_enable('false') + end + it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(false) } + it { is_expected.to contain_service('puppet-run.timer').with_ensure(false) } + it do + is_expected.to contain_cron('puppet') + .with_command("#{bindir}/puppet agent --config #{confdir}/puppet.conf --onetime --no-daemonize") + .with_user('root') + .with_minute(%w[10 40]) + .with_hour('*') + end + else + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(true) } + it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(false) } + it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(false) } + it { is_expected.not_to contain_service('puppet-run.timer') } + it do + is_expected.to contain_cron('puppet') + .with_command("#{bindir}/puppet agent --config #{confdir}/puppet.conf --onetime --no-daemonize") + .with_user('root') + .with_minute(%w[10 40]) + .with_hour('*') + .with_target('/etc/cron.d/puppet') + end + end + end + describe 'when runmode => systemd.timer' do let :params do super().merge(runmode: 'systemd.timer')