我们稍后会看到,清单可以通过模块化的方式放到任意数目的不同文件中(这样可以帮助我们针对大型复杂的站点建立清单结构)。但是一切都还是从site.pp开始。
我们来仔细分析一下这个最简化的清单,它包含两部分:一个包含file定义的node,因为file部分包含在node部分中,这样file部分的定义产生的结果会应用到名为puppetclient的节点上。
通过在puppetclient虚拟机系统上运行Puppet代理,我们可以很容易理解上面描述的内容。
On the puppetclient VM
1
2
3
4
~# sudo puppet agent --verbose --no-daemonize --onetime
info: Caching catalog for puppetclientinfo: Applying configuration version '1395862307'
notice: /Stage[main]//Node[puppetclient]/File[/home/ubuntu/helloworld.txt]/ensure: created
notice: Finished catalog run in 0.03 seconds
或许这看上去没有什么大惊小怪:puppetclient虚拟机上的Puppet代理联系到puppetserver虚拟机上的Puppet master。然后它接收目录,这个目标就是在master上定义的所有和这个指定客户端有关的清单。如果你感兴趣的话,这个目录被存在一个yaml结构中,它存储在 /var/lib/puppet/client_yaml/catalog/puppetclient.yaml 中,这不仅仅是复制了我们的.pp清单,而是通过对清单进行解析,生成的一个关于目标配置信息的编译版本。
接下来,Puppet代理开始采取行动——当且仅当满足以下条件才会采取行动:Puppet代理会比较清单中期望的状况和目标节点上清单的状况,如果其中有一些不同(如果目标节点上找到的状况并没有同步到期望达到的状况)——那么代理就会做任何必需的操作来移除这些区别,来实现目标状况。
在我们这个特定的示例中,代理知道在目标节点的/home/ubuntu目录下,应该有一个名为helloworld.txt的文件,这个文件的所有者和所在组是ubuntu,用户对该文件的访问权限是0644。然而,当检查本地系统时,发现并没有发现这个文件。代理会采取行动,来创建这个期待中的文件。
我们可以通过再次运行代理来验证这个行为:
On the puppetclient VM
1
2
3
4
~# sudo puppet agent --verbose --no-daemonize --onetime
info: Caching catalog for puppetclient
info: Applying configuration version '1395862542'
notice: Finished catalog run in 0.03 seconds
如我们所见,这次代理并没有做任何事情,这是因为目标节点的状况已经满足了。那如果我们修改目标节点上的状况会怎么样呢?让我们来修改这个文件的访问模式:
在 puppetclient VM 上
~# chmod 0640 /home/ubuntu/helloworld.txt
然后再次运行代理:
在 puppetclient VM 上
info: Caching catalog for puppetclient
info: Applying configuration version '1395862307'
notice: /Stage[main]//Node[puppetclient]/File[/home/ubuntu/helloworld.txt]/ensure: created
notice: Finished catalog run in 0.03 seconds
代理注意到了区别,然后通过修改文件访问模式来移除了这个区别。
如果我们修改了文件的内容,会发生什么呢?
在 puppetclient VM 上
~# echo "This is a test" > /home/ubuntu/helloworld.txt
…这时运行代理?
在 puppetclient VM 上
然后,我们需要允许Puppet客户端来访问这个文件,为此,我们需要修改puppetserver虚拟机上的/etc/puppet/fileserver.conf文件,添加一个allow *语句:
/etc/puppet/fileserver.conf on puppetserver
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# This file consists of arbitrarily named sections/modules
# defining where files are served from and to whom
# Define a section 'files'
# Adapt the allow/deny settings to your needs. Order
# for allow/deny does not matter, allow always takes precedence
# over deny
info: Caching catalog for puppetclient
info: Applying configuration version '1395878127'
info: FileBucket adding {md5}ff22941336956098ae9a564289d1bf1b
info: /Stage[main]//Node[puppetclient]/File[/home/ubuntu/helloworld.txt]: Filebucketed /home/ubuntu/helloworld.txt to puppet with sum ff22941336956098ae9a564289d1bf1b
notice: /Stage[main]//Node[puppetclient]/File[/home/ubuntu/helloworld.txt]/content: content changed '{md5}ff22941336956098ae9a564289d1bf1b' to '{md5}770b95bb61d5b0406c135b6e42260580'
notice: Finished catalog run in 0.09 seconds