Puppet Class: puppet::agent::schedule

Defined in:
manifests/agent/schedule.pp

Summary

Puppet agent cron settings

Overview

Puppet agent cron settings

Examples:

include puppet::agent::schedule

Parameters:

  • enable (Boolean) (defaults to: true)
  • job_name (String) (defaults to: 'puppet agent run')
  • job_arguments (Array[String]) (defaults to: [ '--onetime', '--no-daemonize', '--no-usecacheonfailure', '--detailed-exitcodes', '--no-splay', ])
  • verbose (Boolean) (defaults to: true)
  • reboot_job (Boolean) (defaults to: true)
  • file_backups_cleanup (Boolean) (defaults to: true)
  • file_backups_ttl (Integer) (defaults to: 45)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'manifests/agent/schedule.pp', line 16

class puppet::agent::schedule (
  Boolean $enable = true,
  String $job_name = 'puppet agent run',
  Array[String] $job_arguments = [
    '--onetime',
    '--no-daemonize',
    '--no-usecacheonfailure',
    '--detailed-exitcodes',
    '--no-splay',
  ],
  Boolean $verbose = true,
  Boolean $reboot_job = true,
  Boolean $file_backups_cleanup = true,
  Integer $file_backups_ttl = 45,
) {
  $agent_run_minute = fqdn_rand(60, $job_name)

  if $verbose {
    $verbose_argument = ['--verbose']
  }
  else {
    $verbose_argument = []
  }

  $agent_run_arguments = join($job_arguments + $verbose_argument, ' ')

  if $enable {
    cron { $job_name:
      command     => "/opt/puppetlabs/bin/puppet agent ${agent_run_arguments}",
      hour        => absent,
      minute      => $agent_run_minute,
      month       => absent,
      monthday    => absent,
      user        => 'root',
      weekday     => absent,
      environment => 'PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin',
    }
  }

  if $enable and $reboot_job {
    cron { "${job_name} on boot":
      command     => "/opt/puppetlabs/bin/puppet agent ${agent_run_arguments}",
      special     => 'reboot',
      user        => 'root',
      environment => 'PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin',
    }
  }

  if $file_backups_cleanup {
    cron { 'clientbucket cleanup':
      command => "find /opt/puppetlabs/puppet/cache/clientbucket -type f -mtime +${file_backups_ttl} -delete",
      hour    => '5',
      minute  => fqdn_rand(60, 'clientbucket cleanup'),
    }
  }
}