Skip to content

Instantly share code, notes, and snippets.

@KrisBuytaert
Created June 15, 2012 14:35
Show Gist options
  • Save KrisBuytaert/2936773 to your computer and use it in GitHub Desktop.
Save KrisBuytaert/2936773 to your computer and use it in GitHub Desktop.
class manifests::puppetclient {
# The puppetmaster already has puppet::params defined and
# should not be redefined here.
case $::hostname {
/^puppetmaster/: {
$puppetfrequency = '*/5'
## puppet::params is already defined.
}
default: {
class {'puppet::params':
servername => hiera('puppetmaster'),
prerun_command => '/usr/bin/yum clean all',
}
include puppet
$puppetfrequency = 'random'
}
}
## Global configuration (both puppet agents and server)
class{'puppet::cron':
minute => $puppetfrequency,
sleep => 'random',
}
}
class puppet::cron (
$ensure = 'present',
$user = 'root',
$command = undef,
$sleep = undef,
$minute = undef,
$hour = undef,
$month = undef,
$monthday = undef,
$weekday = undef
) {
case $sleep {
'random': {
$seconds = fqdn_rand(60000) / 1000
$sleepcmd = "sleep ${seconds};"
}
undef: {
$sleepcmd = ''
}
default: {
$sleepcmd = "sleep ${sleep};"
}
}
case $minute {
'random': {
$min1 = fqdn_rand(30)
$min2 = $min1 + 30
$minutes = [$min1, $min2]
}
default: {
$minutes = $minute
}
}
$croncommand = $command ? {
undef => "${sleepcmd} puppet agent --onetime",
default => "${sleepcmd}${command}",
}
cron {'puppet_cron_client':
ensure => $ensure,
user => $user,
command => $croncommand,
minute => $minutes,
hour => $hour,
month => $month,
monthday => $monthday,
weekday => $weekday,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment