Project

General

Profile

« Previous | Next » 

Revision 1c0eed2c

Added by Ohad Levy about 12 years ago

adds basic cron handling for puppet runs

View differences:

lib/parser/functions/ip_to_cron.rb
# provides a "random" value to cron based on the last bit of the machine IP address.
# used to avoid starting a certain cron job at the same time on all servers.
# if used with no parameters, it will return a single value between 0-59
# first argument is the occournce within a timeframe, for example if you want it to run 2 times per hour
# the second argument is the timeframe, by default its 60 minutes, but it could also be 24 hours etc
#
# example usage
# ip_to_cron() - returns one value between 0..59
# ip_to_cron(2) - returns an array of two values between 0..59
# ip_to_cron(2,24) - returns an array of two values between 0..23
module Puppet::Parser::Functions
newfunction(:ip_to_cron, :type => :rvalue) do |args|
occours = (args[0] || 1).to_i
scope = (args[1] || 60).to_i
ip = lookupvar('ipaddress').to_s.split('.')[3].to_i
base = ip % scope
if occours == 1
base
else
(1..occours).map { |i| (base - (scope / occours * i)) % scope }.sort
end
end
end
manifests/cron.pp
class puppet::cron inherits puppet::service {
include puppet
Service['puppet'] {
enable => false,
ensure => undef,
}
cron {'puppet':
command => "/usr/sbin/puppetd --config ${puppet::params::dir}/puppet.conf -o",
user => root,
minute => ip_to_cron($puppet::params::cron_interval, $puppet::params::cron_range),
}
}
manifests/params.pp
$apache_conf_dir = $foreman::params::apache_conf_dir
$app_root = "${dir}/rack"
$ssl_dir = '/var/lib/puppet/ssl'
$master_package = $::operatingsystem ? {
/(Debian|Ubuntu)/ => ['puppetmaster'],
default => ['puppet-server'],
}
$cron_range = 60 # the maximum value for our cron
$cron_interval = 2 # the amount of values within the $cron_range
}
manifests/service.pp
class puppet::service {
service {'puppet': require => Class['puppet::install'] }
}

Also available in: Unified diff