一个节点的目录结构可以任意定义,只要在site.pp配置文件中import即可。
建议采用如下目录结构配置:
节点信息:/etc/puppet/manifests/nodes
模块信息:/etc/puppet/modules
现在学习配置简单的File资源,创建文件,并写入’Hello World‘。
1.创建file-helloworld模块
mkdir -p /etc/puppet/modules/
file-helloworld/{manifests,templates,files
}
vim
/etc/puppet/modules/
file-helloworld/
manifests/init.pp
class file-helloworld {
file { "/root/hostname.txt": content => "Hello world!";}
}
2.创建测试节点app-192.168.9.158.centos.test.com
mkdir -p /etc/puppet/manifests/nodes
node 'app-192.168.9.158.centos.test.com' {
include file-helloworld
}
3.最后将测试节点载入到Puppet,也就是修改site.pp配置文件。
vim /etc/puppet/manifests/site.pp
追加一行
import "nodes/app-192.168.9.158.centos.test.com.pp"
到此一个测试节点配置完毕,接下来需要检查配置文件的语法。
检查配置文件分两步经行
第一步在服务端
puppet parser validate /etc/puppet/modules/file-helloworld/manifests/init.pp
看是否提示错误,无错误提示则经行下一步。
第二步在客户端
通过添加--noop参数来实现,验证配置,模拟执行。
[root@app-192 ~]# puppet agent --test --noop
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for app-192.168.9.158.centos.test.com
Info: Applying configuration version '1464588576'
Notice: /Stage[main]/File-helloworld/File[/root/hostname.txt]/ensure: current_value absent, should be file (noop)
Notice: Class[File-helloworld]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.17 seconds
客户端运行配置
[root@app-192 ~]# puppet agent --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for app-192.168.9.158.centos.test.com
Info: Applying configuration version '1464588576'
Notice: /Stage[main]/File-helloworld/File[/root/hostname.txt]/ensure: defined content as '{md5}86fb269d190d2c85f6e0468ceca42a20'
Notice: Finished catalog run in 0.24 seconds
查看运行结果
[root@app-192 ~]# ll hostname.txt
-rw-r--r-- 1 root root 12 5月 30 14:13 hostname.txt