Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions manifests/agent/service/cron.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -18,6 +19,7 @@
user => root,
hour => $_hour,
minute => $_minute,
target => $target,
}
} else{
cron { 'puppet':
Expand Down
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
#
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion manifests/server/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
}
}
}
Expand Down
48 changes: 48 additions & 0 deletions spec/classes/puppet_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also have the with_target()?

.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')
Expand Down