我正在尝试/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)
我想在我的模板中包含已定义主机的列表,但我不知道如何迭代资源及其属性。我尝试使用字符串连接,但无法使其工作并且不是很优雅。
如何遍历所有定义的主机并从模板中包含它们?
puppet ×1