我试图用puppet来pipe理我的/etc/hosts文件,但是我不喜欢内部的'host'types,如果可能的话我想使用我自己的模板。
因此,我定义了一个“主机”资源:
# Basic hosts configuration class hosts { # Host resource define host ( $address, $names ) { } Network::Hosts::Host { before => File['/etc/hosts'] } # Configure hosts file file { "/etc/hosts": ensure => present, checksum => md5, owner => root, group => root, mode => 0644, content => template("network/hosts.erb"), }
在其他地方,我定义主机资源:
network::hosts::host { 'puppet.test.lan': address => '192.168.56.101', names => 'puppet', }
我想在我的模板中包含定义的主机的列表,但我不知道如何迭代资源及其属性。 我尝试使用string连接,但不能使其工作,并不是很优雅。
我如何遍历所有我定义的主机,并从模板中包含它们?
您可以使用RIPienaar的puppet-concat模块,您可以在许多较小的文件或模板中构build单个文件。
这个定义看起来像这样:
define host($address, $names) { concat::fragment{"hosts-$address": target => "/etc/hosts", content => template("network/hosts_single.erb") } }
hosts_single.erb模板将代表文件中的一行。 你也可能为头添加一个片段,并设置order => "01"以确保它位于生成文件的顶部(默认值为10)。
我会查看一下augeas库来pipe理/etc/hosts文件中的条目。 这是Puppet的先决条件,所以它已经安装。 您可能需要下载额外的augeas软件包才能访问augtool命令行实用程序。 这对于Puppet集成之前的testing非常有用。
主机文件条目列在主站点上: http : //augeas.net/tour.html
要么
http://honglus.blogspot.com/2012/01/augeas-quick-start.html
我想你也可以分发一个标准的主机文件,只需修改每个主机需要唯一的行…