我正在尝试为具有以下属性的厨师制作食谱:
default['web-server']['hosts'] = [ { host: "some-ip", server: "some-server", port: "9000" } ]
这个想法是迭代它以创建配置文件(在本例中为 lighttpd),如下所示:
<% if node['web-server']['hosts'].length > 0 -%>
<% node['web-server']['hosts'].each do |host| -%>
$HTTP["host"] =~ "<%= host.host %>" {
proxy.balance = "round-robin" proxy.server = (
"" => (
"play" => (
"host" => "<%= host.server %>",
"port" => <%= host.port %>
)
)
)
}
<% end -%>
<% else -%>
<% end -%>
但是,在chef-client
测试节点上运行时,我收到了以下信息:
FATAL: Chef::Mixin::Template::TemplateError: undefined method `host' for #<Mash:0x00000002b9a878>
循环哈希数组的正确方法是什么?