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

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

4

2 回答 2

5

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

于 2012-03-14T03:30:14.127 回答
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是你的常用食谱清单。

于 2017-09-14T14:54:16.663 回答