cron { 'resource title':
name => # (namevar) The symbolic name of the cron job. This name is
ensure => # The basic property that the resource should be...
command => # The command to execute in the cron job. The...
environment => # Any environment settings associated with this...
hour => # The hour at which to run the cron job. Optional;
minute => # The minute at which to run the cron job...
month => # The month of the year. Optional; if specified...
monthday => # The day of the month on which to run the...
provider => # The specific backend to use for this `cron...
special => # A special value such as 'reboot' or 'annually'...
target => # The name of the crontab file in which the cron...
user => # The user who owns the cron job. This user must...
weekday => # The weekday on which to run the command...
# ...plus any applicable metaparameters.
}
class cron::ntpdate {
cron {"ntpdate":
ensure => present,
command => '/usr/sbin/ntpdate 1.cn.pool.ntp.org',
user => 'root',
minute => '*/5',
}
}
node节点中添加此计划任务.
1
2
3
4
5
6
7
8
9
10
11
node /sh-(proxy|web)\d+/ inherits base {
case $::hostname {
/sh-proxy\d+/: {
include nginx
}
"sh-web1": {
include haproxy
include cron::ntpdate
}
}
}
客户端同步ntpdate.
1
2
3
4
5
6
7
8
9
10
[iyunv@sh-web1 haproxy]# puppet agent -t
Notice: Ignoring --listen on onetime run
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for sh-web1.localdomain
Info: Applying configuration version '1508433121'
Notice: /Stage[main]/Admin/Exec[selinux]/returns: executed successfully
Notice: /Stage[main]/Cron::Ntpdate/Cron[ntpdate]/ensure: created
Notice: Finished catalog run in 0.43 seconds
查看计划任务.
1
2
3
4
5
6
7
[iyunv@sh-web1 haproxy]# crontab -l
# HEADER: This file was autogenerated at Fri Oct 20 01:12:02 +0800 2017 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: ntpdate
*/5 * * * * /usr/sbin/ntpdate 1.cn.pool.ntp.org
示例二:
做一个ping计划任务,每天的2,4点执行ping,注意使用"[]".
1
2
3
4
5
6
7
8
9
10
11
12
node /sh-(proxy|web)\d+/ inherits base {
case $::hostname {
/sh-proxy\d+/: {
include nginx
}
"sh-web1": {
include haproxy
include cron::ntpdate
include cron::ping
}
}
}
[iyunv@sh-web1 haproxy]# puppet agent -t
Notice: Ignoring --listen on onetime run
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for sh-web1.localdomain
Info: Applying configuration version '1508433611'
Notice: /Stage[main]/Admin/Exec[selinux]/returns: executed successfully
Notice: /Stage[main]/Cron::Ping/Cron[ping]/ensure: created
Notice: Finished catalog run in 0.42 seconds
crontab计划任务查看:
1
2
3
4
5
6
7
8
9
[iyunv@sh-web1 haproxy]# crontab -l
# HEADER: This file was autogenerated at Thu Oct 19 17:19:52 +0800 2017 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: ntpdate
*/5 * * * * /usr/sbin/ntpdate 1.cn.pool.ntp.org
# Puppet Name: ping
* 2,4 * * * ping -c1 www.baidu.com 2>&1 >> /dev/null
[iyunv@sh-web1 haproxy]# puppet agent -t
Notice: Ignoring --listen on onetime run
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for sh-web1.localdomain
Info: Applying configuration version '1508433856'
Notice: /Stage[main]/Admin/Exec[selinux]/returns: executed successfully
Notice: /Stage[main]/Cron::Ping/Cron[ping]/minute: defined 'minute' as '*/10'
Notice: /Stage[main]/Cron::Ping/Cron[ping]/hour: hour changed '2,4' to '2-4'
Notice: Finished catalog run in 0.36 seconds
计划任务查看.
1
2
3
4
5
6
7
8
9
[iyunv@sh-web1 haproxy]# crontab -l
# HEADER: This file was autogenerated at Thu Oct 19 17:23:56 +0800 2017 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: ntpdate
*/5 * * * * /usr/sbin/ntpdate 1.cn.pool.ntp.org
# Puppet Name: ping
*/10 2-4 * * * ping -c1 www.baidu.com 2>&1 >> /dev/null