Chef: can I use common startup list items for each environment?

I use the environment in the chef and I want to use start lists for each environment. The problem is that I do not want to repeat myself (for example, I'm doing it now). Example:

{
  "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": {

  }
}

Is there any way to avoid repeating this?

      "role[base]",
      "recipe[mysql::client]",
      "recipe[myapp]",

I just want the environment start lists not to go out of sync and interrupt the deployment.

+5
source share
2 answers

No at this time. Thus, roles are purely declarative and not dynamic. You can create a role that includes these three elements and include them in the startup lists of the environment.

+5
source

This may not be possible in JSON, but it is possible if you use Ruby DSL to define your role.

:

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 - .

0

All Articles