我正在努力让它工作,但不明白我哪里做错了,有人可以指导我如何纠正吗?
基本上,我想在我的 nodes.pp 中获取一个数组,然后通过循环并写入每个元素的一行来由我的模板文件使用该数组:
节点.pp:
node test{
net::addr { 'routing':
$routes = {
route1 => {
address => '172.29.54.70',
netmask => '255.255.255.0',
gateway => '172.29.54.65',
dev => 'eth0',
},
route2 => {
address => '192.168.1.3',
netmask => '255.255.255.0',
gateway => '192.168.1.1',
dev => 'eth3',
},
}
}
}
当我运行 Puppet 客户端时,我不断收到以下信息:
错误:无法从远程服务器检索目录:服务器上出现错误 400:无法解析环境生产:节点 test.myincorp.net 上的 /etc/puppet/manifests/nodes/test.pp:3 处的“=”处出现语法错误;预期为“}”
地址.pp
define net::addr (
$address='',
$netmask='',
$gateway='',
$dev='',
) {
file { "route-${name}":
ensure => 'present',
mode => '0644',
owner => 'root',
group => 'root',
path => "/etc/sysconfig/network-scripts/route-${name}",
content => template('network/addr.erb'),
}
}
模板:addr.erb:
<% routes.each do |route| -%>
<%= route['address'] %> <%= route['netmask'] %> <%= route['gateway'] %> <%= route['dev'] %>
<% end -%>
<% end -%>
<% end -%>
有人能帮我解决上述问题吗?
谢谢丹
答案1
您似乎打算将路由数组传递给路由名称中的 net::addr,但您已将其定义为采用每条路由的 4 个键,而不是路由数组。尝试以下操作,看看效果是否更好。
node test{
net::addr { 'routing':
routes => {
route1 => {
address => '172.29.54.70',
netmask => '255.255.255.0',
gateway => '172.29.54.65',
dev => 'eth0',
},
route2 => {
address => '192.168.1.3',
netmask => '255.255.255.0',
gateway => '192.168.1.1',
dev => 'eth3',
},
}
}
}
和
define net::addr (
$routes={},
) {
file { "route-${name}":
ensure => 'present',
mode => '0644',
owner => 'root',
group => 'root',
path => "/etc/sysconfig/network-scripts/route-${name}",
content => template('network/addr.erb'),
}
}
编辑:修正拼写错误,填充以满足编辑字符限制