[iyunv@puppet ~]# yum -y install tree
[iyunv@puppet ~]# tree /etc/puppet/modules/ntp/
/etc/puppet/modules/ntp/
├── files
├── manifests
│ └── init.pp
└── templates
(2)定义ntp类
1
2
3
4
5
6
7
8
9
10
[iyunv@puppet ~]# vi /etc/puppet/modules/ntp/manifests/init.pp
class ntp {
cron { "ntpdate": #系统已默认安装ntpdate,也可以定义package来确保安装ntpdate包
command => "/usr/sbin/ntpdate 65.55.56.206",
ensure => present,
user => root,
hour => '*/2', #每两小时同步一次
minute => 0,
}
}
说明:保持良好的代码编写习惯,注意缩进和=>对齐 (3)定义节点文件,调用模块
1
2
3
4
[iyunv@puppet ~]# vi /etc/puppet/manifests/centostest.pp
node "centostest.ewin.com" {
include ntp
}
(4)应用节点文件
1
2
[iyunv@puppet ~]# vi /etc/puppet/manifests/site.pp
import "centostest.pp"
说明:以上三个文件,一个调用一个;定义类>>定义节点(调用类)>>调用节点
2、客户端测试puppet (1)测试执行puppet
1
2
3
4
5
6
7
8
9
[iyunv@centostest ~]# puppet agent --server puppet.ewin.com --test --noop
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for centostest.ewin.com
Info: Applying configuration version '1415239491'
Notice: /Stage[main]/Ntp/Cron[ntpdate]/ensure: current_value absent, should be present (noop)
Notice: Class[Ntp]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.15 seconds
说明:--noop参数表示不真正执行,只是测试puppet模块应用成功与否 (2)查看计划任务
1
2
3
4
5
6
7
[iyunv@centostest ~]# crontab -e
#HEADER: This file was autogenerated at Thu Nov 06 10:09:29 +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.
# Puppet Name: ntpdate
0 */2 * * * /usr/sbin/ntpdate 65.55.56.206