diff --git a/manifests/agent/service/cron.pp b/manifests/agent/service/cron.pp index 9dff929..f908c1a 100644 --- a/manifests/agent/service/cron.pp +++ b/manifests/agent/service/cron.pp @@ -1,27 +1,20 @@ class puppet::agent::service::cron ( - $enabled = false, + Boolean $enabled = false, ) { - if ! ('cron' in $::puppet::unavailable_runmodes) { - case $enabled { - true: { - $command = $::puppet::cron_cmd ? { - undef => "${::puppet::puppet_cmd} agent --config ${::puppet::dir}/puppet.conf --onetime --no-daemonize", - default => $::puppet::cron_cmd, - } - - $times = ip_to_cron($::puppet::runinterval) - cron { 'puppet': - command => $command, - user => root, - hour => $times[0], - minute => $times[1], - } + unless 'cron' in $::puppet::unavailable_runmodes { + if $enabled { + $command = pick($::puppet::cron_cmd, "${::puppet::puppet_cmd} agent --config ${::puppet::dir}/puppet.conf --onetime --no-daemonize") + $times = ip_to_cron($::puppet::runinterval) + cron { 'puppet': + command => $command, + user => root, + hour => $times[0], + minute => $times[1], } - false: { - cron { 'puppet': - ensure => absent, - } + } else{ + cron { 'puppet': + ensure => absent, } } } } diff --git a/manifests/agent/service/systemd.pp b/manifests/agent/service/systemd.pp index b1fb8dd..ec61d37 100644 --- a/manifests/agent/service/systemd.pp +++ b/manifests/agent/service/systemd.pp @@ -1,70 +1,66 @@ class puppet::agent::service::systemd ( - $enabled = false, + Boolean $enabled = false, ) { - if ! ('systemd.timer' in $::puppet::unavailable_runmodes) { + unless 'systemd.timer' in $::puppet::unavailable_runmodes { exec { 'systemctl-daemon-reload-puppet': refreshonly => true, path => $::path, command => 'systemctl daemon-reload', } - case $enabled { - true: { - # Use the same times as for cron - $times = ip_to_cron($::puppet::runinterval) + if $enabled { + # Use the same times as for cron + $times = ip_to_cron($::puppet::runinterval) - $command = $::puppet::systemd_cmd ? { - undef => "${::puppet::puppet_cmd} agent --config ${::puppet::dir}/puppet.conf --onetime --no-daemonize --detailed-exitcode --no-usecacheonfailure", - default => $::puppet::systemd_cmd, - } + $command = $::puppet::systemd_cmd ? { + undef => "${::puppet::puppet_cmd} agent --config ${::puppet::dir}/puppet.conf --onetime --no-daemonize --detailed-exitcode --no-usecacheonfailure", + default => $::puppet::systemd_cmd, + } - $randomizeddelaysec = $::puppet::systemd_randomizeddelaysec + $randomizeddelaysec = $::puppet::systemd_randomizeddelaysec - file { "/etc/systemd/system/${::puppet::systemd_unit_name}.timer": - content => template('puppet/agent/systemd.puppet-run.timer.erb'), - notify => [ - Exec['systemctl-daemon-reload-puppet'], - Service['puppet-run.timer'], - ], - } + file { "/etc/systemd/system/${::puppet::systemd_unit_name}.timer": + content => template('puppet/agent/systemd.puppet-run.timer.erb'), + notify => [ + Exec['systemctl-daemon-reload-puppet'], + Service['puppet-run.timer'], + ], + } - file { "/etc/systemd/system/${::puppet::systemd_unit_name}.service": - content => template('puppet/agent/systemd.puppet-run.service.erb'), - notify => Exec['systemctl-daemon-reload-puppet'], - } + file { "/etc/systemd/system/${::puppet::systemd_unit_name}.service": + content => template('puppet/agent/systemd.puppet-run.service.erb'), + notify => Exec['systemctl-daemon-reload-puppet'], + } - service { 'puppet-run.timer': - ensure => running, - provider => 'systemd', - name => "${::puppet::systemd_unit_name}.timer", - enable => true, - require => Exec['systemctl-daemon-reload-puppet'], - } + service { 'puppet-run.timer': + ensure => running, + provider => 'systemd', + name => "${::puppet::systemd_unit_name}.timer", + enable => true, + require => Exec['systemctl-daemon-reload-puppet'], + } + } else { + # Reverse order - stop, delete files, exec + service { 'puppet-run.timer': + ensure => stopped, + provider => 'systemd', + name => "${::puppet::systemd_unit_name}.timer", + enable => false, + before => [ + File["/etc/systemd/system/${::puppet::systemd_unit_name}.timer"], + File["/etc/systemd/system/${::puppet::systemd_unit_name}.service"], + ], } - false: { - # Reverse order - stop, delete files, exec - service { 'puppet-run.timer': - ensure => stopped, - provider => 'systemd', - name => "${::puppet::systemd_unit_name}.timer", - enable => false, - before => [ - File["/etc/systemd/system/${::puppet::systemd_unit_name}.timer"], - File["/etc/systemd/system/${::puppet::systemd_unit_name}.service"], - ], - } - file { "/etc/systemd/system/${::puppet::systemd_unit_name}.timer": - ensure => absent, - notify => Exec['systemctl-daemon-reload-puppet'], - } + file { "/etc/systemd/system/${::puppet::systemd_unit_name}.timer": + ensure => absent, + notify => Exec['systemctl-daemon-reload-puppet'], + } - file { "/etc/systemd/system/${::puppet::systemd_unit_name}.service": - ensure => absent, - notify => Exec['systemctl-daemon-reload-puppet'], - } + file { "/etc/systemd/system/${::puppet::systemd_unit_name}.service": + ensure => absent, + notify => Exec['systemctl-daemon-reload-puppet'], } - default: { fail('puppet::agent::service::systemd::enabled should be true or false') } } } }