我正在尝试/etc/hosts
使用 puppet管理我的文件,但我不喜欢内部的“主机”类型,如果可能,我想使用我自己的模板。
因此,我定义了一个“主机”资源:
# 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"),
}
Run Code Online (Sandbox Code Playgroud)
在其他地方,我定义了主机资源:
network::hosts::host { 'puppet.test.lan':
address => '192.168.56.101',
names => 'puppet',
}
Run Code Online (Sandbox Code Playgroud)
我想在我的模板中包含已定义主机的列表,但我不知道如何迭代资源及其属性。我尝试使用字符串连接,但无法使其工作并且不是很优雅。
如何遍历所有定义的主机并从模板中包含它们?
我会查看augeas 库来管理/etc/hosts
文件中的条目。它是 Puppet 的先决条件,所以它已经安装了。您可能需要下载额外的 augeas 包才能访问augtool
命令行实用程序。这对于在 Puppet 集成之前进行测试很有用。
主站点上列出的主机文件条目示例:http : //augeas.net/tour.html
或者
http://honglus.blogspot.com/2012/01/augeas-quick-start.html
我想你也可以分发一个标准的主机文件,只需修改每个主机需要唯一的行......