Cron资源
参数
除了用户和command两个参数以外,其他的参数都是可选项.
Command:rontab要执行的命令, 环境变量按照系统本地规则进行管理,推荐使用绝对路径.
Ensure:定该资源是否启用,可设置成true或false
Environment:crontab环境里面指定环境变量,例如 PATH=/bin:/usr/bin:/usr/sbin.
Hour:行crontab的小时,可设置成0-23
Minute:行crontab的分钟,可设置成0-59
Month:置crontab运行的月份,1-12
       Monthday:个月份中的日子,1-31
Name:crontab的名字,这个名字用于管理员区分不同的crontab,以及puppet管理各种资源关系.
Provider:定provider,可用的provider有
User:该crontab加到那个用户的crontab列表,默认是运行puppet的用户
Weekday:行crontab的星期数,0-7

server asa.kanbox.net
Client puppet.kanbox.com
案列:
1    Cron计划任务测试用例    
       在site.pp中加入如下内容
       
cron{ echo: 
        command=>"echo \"This is cron job\"", 
        user=>root, 
        #hour=>[3,5], 
        minute=>'*/2'; 
    } 
    
    
2  用Client进程测试:
[root@client1 ~]
# puppetd   --server  asa.kanbox.net --test  
notice: Ignoring --listen on onetime run  
info: Caching catalog for client1.centos 
info: Applying configuration version '1329980213' 
notice: /Stage[main]//Node[default]/Cron[echo]/ensure: created 
notice: Finished catalog run in 0.50 seconds 

3  检查Cron任务列表
[root@client1 ~]
# crontab -l 
# HEADER: This file was autogenerated at Thu Feb 23 14:56:53 +0800 2012 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.
# Puppet Name: echo
*/2 * * * * echo "This is cron job" 

4 配置puppet客户机同步master的cron任务。默认是半小时一次,但是有时候我们需要立即生效。而不要手动执行呢?所有我们需要配置客户端的同步时间
客户端设置:vi /etc/puppet/puppet.conf 增加
   runinterval = 30   秒
   listen = true
vi /etc/puppet/puppet.conf
[main]
# The Puppet log directory.
# The default value is '$vardir/log'.
logdir = /var/log/puppet
# Where Puppet PID files are kept.
# The default value is '$vardir/run'.
rundir = /var/run/puppet
# Where SSL certificates are kept.
# The default value is '$confdir/ssl'.
ssldir = $vardir/ssl
[agent]
# The file in which puppetd stores a list of the classes
# associated with the retrieved configuratiion. Can be loaded in
# the separate ``puppet`` executable using the ``--loadclasses``
# option.
# The default value is '$confdir/classes.txt'.
classfile = $vardir/classes.txt
# Where puppetd caches the local configuration. An
# extension indicating the cache format is added automatically.
# The default value is '$confdir/localconfig'.
localconfig = $vardir/localconfig
runinterval = 30
listen = true
5  修改master端/etc/sysconfig/puppet
vim /etc/sysconfig/puppet
PUPPET_SERVER=asa.kanbox.net  //改为你对应的puppetmaster的主机名  
新建namespaceauth.conf这个文件,vi /etc/puppet/namespaceauth.conf添加如下内容:  
[puppetrunner]  
allow *  
 
6  还需要修改auth.conf。  
在path /之前添加下内容:  
path /run  
method save  
allow *  
path /  
auth any  
即可!  
然后重启客户端:/etc/init.d/puppet restart  
7  在服务器端测试一下:执行一下命令  
新建namespaceauth.conf这个文件,vi /etc/puppet/namespaceauth.conf添加如下内容:  
[puppetrunner]  
allow *  
 
8  还需要修改auth.conf(经过检查 跟默认文件一致)  
在path /之前添加下内容,加粗部分:  
path /run  
method save  
allow *  
path /  
auth any  
即可!  
9  然后重启客户端:/etc/init.d/puppet restart  
10 在服务器端测试一下:执行一下命令  
puppetrun -p 10 –host puppet.kanbox.com