厨师:我可以共享常见的每环境运行列表项吗?

时间:2012-03-13 17:26:02

标签: ruby deployment 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]",

我只是想避免环境运行列表失去同步并破坏部署。

2 个答案:

答案 0 :(得分:5)

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

答案 1 :(得分: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是您常用食谱的列表。