2012-03-13 24 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是您共同食譜清單。

相關問題