我在chef中使用环境,我想使用每个环境的运行列表。问题是我不想重复自己(就像我现在做的那样)。示例:
{
"name": "myapp",
"default_attributes": {
},
"json_class": "Chef::Role",
"env_run_lists": {
"production": [
# Has less packages because services are spread across specialized nodes
"role[base]",
"recipe[mysql::client]",
"recipe[myapp]"
],
"staging": [
# Has less packages because services are spread across specialized nodes
"role[base]",
"recipe[mysql::client]",
"recipe[myapp]"
],
"development": [
"role[base]",
"recipe[mysql::client]",
"recipe[myapp]",
"role[utility]",
"role[cache]"
]
},
"run_list": [
],
"description": "The myapp.com core application role",
"chef_type": "role",
"override_attributes": {
}
}
有什么办法可以避免我重复这个吗?
"role[base]",
"recipe[mysql::client]",
"recipe[myapp]",
我只是想避免环境运行列表不同步和破坏部署。
此时没有。角色纯粹是声明性的,而不是动态的。您可以创建一个包含这三项的角色,并将其包含在每个环境的运行列表中。
这在JSON中可能不可能,但如果您使用Ruby DSL来定义您的角色,这是可能的。
这就是你的角色文件的样子:
name "myapp"
description "Description of the role"
base_run_list = [ "role[base]", "recipe[mysql::client]", "recipe[myapp]" ]
env_run_lists "production" => base_run_list, "staging" => base_run_list , "development" => base_run_list + ["role[utility]", "role[cache]"]
base_run_list
是您的常用食谱列表。