环境:master与agent都为ubuntu14.04,
主机名:
master:workgroup.hzg.com
agent:agent.hzg.com
master上的步骤:
在master上创建一个名为test的modules,建立以下文件夹:
mkdir -p /etc/puppet/modules/test/{manifests,templates,files}
进入manifests,创建init.pp,添加以下内容:
class test{ file { "/tmp/$hostname.txt": content => "Hello,world"; } }
$hostname将通过templates中的test.erb文件获取内容,实质是通过facter,编辑templates中的test.erb,添加以下内容:
hostname <%= fqdn %>
编辑/etc/puppet/manifests/nodes/agent.hzg.com.pp,加入以下内容:
node 'agent.hzg.com' { include test }
最后编辑/etc/puppet/manifests/site.pp,追加以下内容:
import "nodes/agent.hzg.com.pp"
最后执行(检查语法):
puppet parser validate /etc/puppet/modules/test/manifests/init.pp
agent上的步骤:
先用--noop模拟执行:
puppet agent --test --server workgroup.hzg.com --noop
提示如下:
Info: Retrieving plugin Info: Caching catalog for agent.hzg.com Info: Applying configuration version '1408282818' Notice: /Stage[main]/Test/File[/tmp/agent.txt]/ensure: current_value absent, should be file (noop) Notice: Class[Test]: Would have triggered 'refresh' from 1 events Notice: Stage[main]: Would have triggered 'refresh' from 1 events Notice: Finished catalog run in 0.05 seconds
没有问题后,即可去掉--noop:
puppet agent --test --server workgroup.hzg.com
提示如下:
Info: Retrieving plugin Info: Caching catalog for agent.hzg.com Info: Applying configuration version '1408282818' Notice: /Stage[main]/Test/File[/tmp/agent.txt]/ensure: defined content as '{md5}7add895cc0518859d8cc85da0ff4756b' Notice: Finished catalog run in 0.06 seconds
检查/tmp/agent.txt,显示:
Hello,world
可以看到,puppet已经创建了以agent节点主机名命名的agent.txt文件
参考《puppet实战》