题
是否可以在Chef Solo的JSON中指定属性值?我有一个独奏。带有运行列表的json,我想在那里指定属性。厨师文档似乎表明我应该可以做类似的事情:
{
"hostname": {
"test": "value2"
},
"default_attributes": {
"hostname": {
"test": "value3"
}
},
"override_attributes": {
"hostname": {
"test": "value4"
}
},
"default": {
"hostname": {
"test": "value5"
}
},
"run_list": [
"recipe[hostname::default]"
]
}
但是,每当我尝试访问我的食谱中的值时:
p node['hostname']['test']
我只是得到属性/默认值中定义的值。rb,如果我没有在那里定义它,我会得到一个nil值。
有没有办法引用这些值?
解决方案
您可以在节点数据中存储的唯一属性级别是 normal
, ,其他所有内容都在收敛开始时重置,并从角色,环境和说明书中重建。你想要像这样的东西:
{
"normal": {
"hostname": {
"test": "something"
}
},
"run_list": [
"recipe[hostname::default]"
]
}
其他提示
我尝试使用上面的示例在chef-solo的JSON文件中设置属性,以及 "normal": {...}
块被完全忽略。运行列表已被读取,但属性似乎从未起作用。
我的命令是:
chef-solo -c /path/to/config_file.rb -j /path/to/file.json
我的JSON文件:
{
"name": "my_json_file",
"description": "JSON run-list and attributes.",
"normal": {
"my_cookbook": {
"git_branch": "staging"
}
},
"run_list": [
"recipe[my_cookbook::recipe1]",
"recipe[my_cookbook::recipe2]",
]
}
在收敛过程中,厨师直接回到了 attributes/default.rb
.JSON值是否正确输入?到目前为止,我唯一的解决方法是为每个创建一个新的配方 "git_branch":
属性我想用chef-solo测试,并将更新的运行列表添加到不同的JSON文件中。从本质上讲,复制整个配方以更改单个 node.normal['my_cookbook']['git_branch']
价值。不用说,这不应该是一个解决方案。
使用厨师14.0.202
跟进:
没有设置JSON文件内的属性优先级与厨师独奏作品。JSON应该类似于以下内容:
{
"name": "my_json_file",
"description": "JSON run-list and attributes.",
"my_cookbook": {
"git_branch": "staging"
},
"run_list": [
"recipe[my_cookbook::recipe1]",
"recipe[my_cookbook::recipe2]",
]
}
不包括 "normal": {...}
或 "default_attributes": {...}
, 等,会传递属性给chef-solo使用。
不隶属于 StackOverflow