每一个cron资源需要一个command属性和user属性以及至少一个周期属性(hour, minute, month, monthday, weekday)。
计划任务的名字不是计划任务的一部分,它是puppet用来存储和检索该资源。假如你指定了一个除了名字其他的都和一个已经存在的计划任务相同,那么这两个计划任务被认为是等效的,并且新名字将会永久地与该计划任务相关联。一旦这种关联建立并写入磁盘之后,你就可以方便的进行计划任务的管理了。可以通过文件的方式来管理计划任务也可以通过计划任务格式来管理计划任务。
随机数:
minute => inline_template("<%= hostname.hash % 60 %>"), hour => inline_template("<%= (hostname+name).hash.abs % 24 %>"), |
时间参数:
分 时 日 月 周 命令
minute hour month monthday weekday command
格式:
cron {"title": ensure => {present|absent}, #present不存在,则添加;absent存在,则删除 command => "命令", #欲执行的命令或脚本路径,也可不写,默认是title user => "用户", #执行该cron的用户身份 minute => "值", #分,同crontab,不写,代表* hour => "值", #时 monthday => "值", #日 month => "值", #月 weekday => "值", #周 }
|
除了用户和command两个参数以外,其他的参数都是可选项.
ensure ensure => {present|absent},
决定该计划任务的目标状态,
present 如该cron不存在,则添加;
absent 如该cron已存在,则删除之
command command => "命令",
欲执行的命令或脚本路径,也可不写,默认是title
user user => "用户",
把该crontab加到那个用户的crontab列表,默认是运行puppet的用户。
minute minute => "值",
运行crontab的分钟,可设置成0-59,同crontab,不写,代表*。
hour hour => "值",
运行crontab的小时,可设置成0-23。
monthday monthday => "值",
一个月份中的日子,1-31。
month month => "值",
设置crontab运行的月份,1-12。
weekda weekday => "值",
运行crontab的星期数,0-7,周日是为0或7。
注:时间属性,不写,代表*;指定多个时间,使用数组,例:[1,3,5]。
实例:
# vi /etc/puppet/manifest/test.pp cron {"ntp time": ensure => present, command => "/sbin/ntpdate asia.pool.ntp.org", user => 'root', minute => 0, hour => '6-13/3', month => [1,3,5,12]; }
#check [root ~]# crontab -l 0 * * * * /etc/webmin/bandwidth/rotate.pl [root ~]# [root ~]# puppet agent --test -vv --server master.perofu.com info: Caching catalog for client.perofu.com info: Applying configuration version '1395082392' notice: /Stage[main]//Cron[ntp time]/ensure: created notice: Finished catalog run in 0.13 seconds [root ~]# crontab -l # HEADER: This file was autogenerated at Tue Mar 18 02:54:41 +0800 2014 by puppet. # HEADER: While it can still be managed manually, it is definitely not recommended. # HEADER: Note particularly that the comments starting with 'Puppet Name' should # HEADER: not be deleted, as doing so could cause duplicate cron jobs. 0 * * * * /etc/webmin/bandwidth/rotate.pl # Puppet Name: ntp time 0 6-13/3 * 1,3,5,12 * /sbin/ntpdate asia.pool.ntp.org
#随机数 vi /etc/puppet/manifests/1.pp
cron {"run-puppet": command => "/usr/sbin/puppet agent --server=master.perofu.com --test >/dev/null 2>&1", minute => inline_template("<%= (hostname+name).hash.abs % 60 %>"), # #minute => inline_template("<%= hostname.hash.abs % 60 %>"), }
# [root ~]# puppet agent --server=master.perofu.com --test notice: Ignoring --listen on onetime run Could not retrieve fact='arp_eth0', resolution='<anonymous>': undefined method `get_arp_value' for Facter::Util::IP:Module Could not retrieve fact='arp_lo', resolution='<anonymous>': undefined method `get_arp_value' for Facter::Util::IP:Module info: Caching catalog for client.perofu.com info: Applying configuration version '1399358355' notice: /Stage[main]//Cron[run-puppet]/ensure: created notice: Finished catalog run in 0.28 seconds [root ~]# [root ~]# [root ~]# crontab -l # HEADER: This file was autogenerated at Tue May 06 14:39:15 +0800 2014 by puppet. # HEADER: While it can still be managed manually, it is definitely not recommended. # HEADER: Note particularly that the comments starting with 'Puppet Name' should # HEADER: not be deleted, as doing so could cause duplicate cron jobs. 0 * * * * /etc/webmin/bandwidth/rotate.pl # Puppet Name: run-puppet 49 * * * * /usr/sbin/puppet agent --server=master.perofu.com --test >/dev/null 2>&1 |
至此,puppet的cron资源就结束了,接下来的是group资源的学习,请听下回分解!!!