Chef 属性,如何获取特定键的值

Chef Attributes, How to get the value of a specific key

我正在尝试管理以下厨师角色。
在这种情况下,属性 node["customer"]["name"] 是一个数组。
在食谱中,我需要获取数组节点 ["customer"]["name"] 第一个元素的值作为 "foo".

"customer" => {
    "name" => {
        ["foo"] => {
            "prod" => {
                "apache" => {
                    "listening" => 81
                },
                "database" => {
                    "type" => "postgres"
                }
            },
            "dev" => {
                "apache" => {
                    "listening" => 81
                },
                "database" => {
                    "type" => "postgres"
                }
            }
        }
    }
}

我做了什么:

node[:customer][:name].each do |customer|
Chef::Log.info("CONFIGURING --- #{customer}")
end

但没想到,变量"customer"包含值

INFO: CONFIGURING --- ["[\"foo\"]", {"prod"=>{"apache"=>{"listening"=>81}, "database"=>{"type"=>"postgres"}}, "dev"=>{"apache"=>{"listening"=>81}, "database"=>{"type"=>"postgres"}}}]

而不只是简单的值"foo"

如何获取简单值 "foo" 而不是整个递归哈希?

谢谢

node[:customer][:name].each do |customer,properties|
  Chef::Log.info("CONFIGURING --- #{customer}")
end

您只是在那里使用 ruby 来迭代散列,您必须告诉 ruby 您不希望获得完整的对象,而只想获得密钥和其他东西其余属性。

不能在 Chef 角色中实现数组。 Chef 角色只能将属性设置为某个值。例如下面的例子应该可以正常工作。

"customer" => {
    "name" => "foo"
}