2012-03-13 41 views
5

我在厨师中使用环境,我想使用每个环境的运行列表。问题是我不想重复自己(就像我现在所做的那样)。例如:厨师:我可以共享每个环境的运行列表项吗?

{ 
    "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]", 

我只是想避免环境运行列表不同步和打破部署。

回答

5

此时,没有。角色纯粹是声明性的,并不是那种动态的。您可以创建一个包含这三个项目的角色,并将其包含在每个环境运行列表中。

+1

不能要求更好的人回答我的问题 - 谢谢! – Kenny 2012-03-15 12:37:06

0

这可能不适用于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是您共同食谱清单。