Reputation: 9152
I am a bit confused about how to use environment runlist in chef. As you can see following role.json. In env_run_lists, you have _default and then we already have the default run_list one. What is the difference? and will the default one run everytime before running the environment 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": {
}
}
Upvotes: 4
Views: 4842
Reputation: 573
What this means in practice is that if you specify a run_list attribute then you do not need to include the _default environment in the env_run_list attribute.
I don't have 50 reputation so I can't comment on Jared Russell's answer, but if I have this in my role definition:
common_run_list = ["recipe[something]", "recipe[something_else]"]
run_list(common_run_list)
env_run_lists(
"dev" => common_run_list + ["recipe[another_thing]"]
)
Then I get the following error:
[2014-02-04T16:38:57-08:00] ERROR: _default key is required in env_run_lists.
So I had to specify the _default key in the env_run_lists even though my run_list is specified.
Upvotes: 2
Reputation: 11372
I agree that this is quite confusing, especially so since the documentation seems to be incorrect with regards to the behaviour I can see by looking at the source.
From reading the source we can see that when the Role
object is constructed it keys the content of the run_list
attribute against the _default environment, and then merges the hash with the contents of the env_run_lists
attribute (overwriting the value for the _default key).
What this means in practice is that if you specify a run_list
attribute then you do not need to include the _default environment in the env_run_list
attribute. If you choose to include the _default environment in the env_run_list
attribute then it will overwrite anything defined in the run_list
attribute.
The one other obvious thing to point out is that if your node is not part of any of the environments defined in the role (_default or otherwise) it will fall back to using the run_list for the _default environment.
Upvotes: 3