【问题标题】:What is the difference between the default run_list and '_default' environment run_list in chef?Chef 中的默认 run_list 和 '_default' 环境 run_list 有什么区别?
【发布时间】:2014-02-05 08:47:52
【问题描述】:

我对如何在厨师中使用环境运行列表有点困惑。 如您所见,下面的 role.json。在 env_run_lists 中,您有 _default,然后我们已经有了默认的 run_list 之一。有什么区别?并且每次运行环境run_list之前都会运行默认的吗?

{
  "name": "webserver",
  "default_attributes": {
  },
  "json_class": "Chef::Role",
  "env_run_lists": {
    "_default": [

    ],
    "production": [

    ],
    "dev": [
      "role[base]",
      "recipe[apache]",
      "recipe[apache::copy_dev_configs]"
    ]
  },
  "run_list": [
    "role[base]",
    "recipe[apache]"
  ],
  "description": "The webserver role",
  "chef_type": "role",
  "override_attributes": {
  }
}

【问题讨论】:

    标签: chef-infra


    【解决方案1】:

    我同意这很令人困惑,尤其是因为documentation 似乎与我通过查看源代码看到的行为不正确。

    通过阅读source,我们可以看到,在构造Role 对象时,它会将run_list 属性的内容与_default 环境相结合,然后将哈希与env_run_lists 属性的内容合并(覆盖 _default 键的值)。

    这实际上意味着,如果您指定run_list 属性,那么您不需要 需要在env_run_list 属性中包含_default 环境。如果您选择在env_run_list 属性中包含_default 环境,那么它将覆盖run_list 属性中定义的任何内容。

    要指出的另一件明显的事情是,如果您的节点不属于角色(_default 或其他)it will fall back to using the run_list for the _default environment 中定义的任何环境。

    【讨论】:

      【解决方案2】:

      这实际上意味着,如果您指定了 run_list 属性,那么您不需要在 env_run_list 属性中包含 _default 环境。

      我没有 50 声望,所以我无法评论 Jared Russell 的回答,但如果我的角色定义中有这个:

      common_run_list = ["recipe[something]", "recipe[something_else]"]
      
      run_list(common_run_list)
      
      env_run_lists(
          "dev" => common_run_list + ["recipe[another_thing]"]
      )
      

      然后我得到以下错误:

      [2014-02-04T16:38:57-08:00] 错误:env_run_lists 中需要 _default 键。

      因此,即使指定了我的 run_list,我也必须在 env_run_lists 中指定 _default 键。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-29
        • 2021-07-25
        • 1970-01-01
        • 1970-01-01
        • 2019-01-29
        • 2019-02-04
        相关资源
        最近更新 更多