玩木偶,我最终在一个嵌套字典/哈希 – 看起来或多或少像 $settings ={ "var1" = { "ip" = "0.0.0.0", "port" = "1234", "option" = ["foo", "bar"], "machines" = { "maschine-1" = { "ip" = "1.2.3.4", "port" = "1234"}, "maschine
          $settings =
{
  "var1" => 
  {
    "ip" => "0.0.0.0",
    "port" => "1234",
    "option" => ["foo", "bar"],
    "machines" =>
    {
      "maschine-1" => { "ip" => "1.2.3.4", "port" => "1234"},
      "maschine-2" => { "ip" => "1.2.3.5", "port" => "1235"},
    }  
  }
} 
 但是,我还没有设法在对应的erb模板中正确解析它.
<% @settings.each_pair do |settings_key, settings_value_hash| %>
<%= settings_value_hash['ip']%>:<%= settings_value_hash['port'] %>
option <% @settings_value_hash['option'].each do |option| -%> <%= option  %>   <% end -%>
<% @{settings_value_hash['machines']}.each_pair do |machine_key, machine_value_hash| %>
  server <%= machine_key %>  <%= machine_value_hash['ip'] %>:<%= machine_value_hash['port'] %>
<% end %> 
 
因此,我可以毫无问题地获取我的顶级词典中的值,即“ip”和“port”,
但是,当我试图进入顶部字典中的数组“选项”或字典“机器”时,puppet会抛出编译错误.
我现在的猜测是,数组和dicts /哈希在Ruby / Puppet中不是“可以”,或者?
干杯并感谢您的想法,
  托马斯
<% @settings.each do |settings_key, settings_value_hash| %>
  <%= "#{settings_value_hash['ip']}:#{settings_value_hash['port']}" %>
  option 
  <% settings_value_hash['option'].each do |option| %> 
    <%= option  %>   
  <% end %>
  <% settings_value_hash['machines'].each do |machine_key, machine_value_hash| %>
    server <%= "#{machine_key} #{machine_value_hash['ip']}:#{machine_value_hash['port']}" %>
  <% end %>
<% end %> 
 另外,为什么您的初始哈希设置为全局$设置,但您通过实例变量@settings访问它.
