在Chef Solo JSON中使用属性 [英] Using attributes in Chef Solo JSON

查看:62
本文介绍了在Chef Solo JSON中使用属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Chef Solo的JSON中指定属性值?我有一个带有运行列表的solo.json,我想在那里指定属性。 Chef文档似乎表明我应该可以执行以下操作:

Is it possible to specify attribute values in Chef Solo's JSON? I have a solo.json with a run list and I would like to specify the attributes there. The Chef documentation seems to indicate it should be possible for me to do something like:

{
    "hostname": {
        "test": "value2"
    },
    "default_attributes": {
        "hostname": {
            "test": "value3"
        }
    },
    "override_attributes": {
        "hostname": {
            "test": "value4"
        }
    },
    "default": {
        "hostname": {
            "test": "value5"
        }
    },
    "run_list": [
        "recipe[hostname::default]"
    ]
}

但是,每当我尝试访问配方中的值时:

However, whenever I try to access the value in my recipe:

p node['hostname']['test']

我只是得到attributes / default.rb中定义的值,如果没有在此定义,我返回零值。

I just get the value defined in attributes/default.rb, and if I do not define it there, I get a nil value back.

是否可以引用这些值?

推荐答案

您可以在节点数据中存储的唯一属性级别是 normal ,其他所有内容在聚合开始时都会重置,并且从角色,环境和食谱中重新构建。您想要这样的东西:

The only level of attributes you can store in the node data is normal, everything else is reset at the start of the converge and rebuilt from roles, environments, and cookbooks. You want something like looks like this:

{
  "normal": {
    "hostname": {
      "test": "something"
    }
  },
  "run_list": [
    "recipe[hostname::default]"
  ]
}

这篇关于在Chef Solo JSON中使用属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆