What is the difference between default run_list and "_default" run_list in a chef?

I'm a little confused about how to use the runtime command in a chef. As you can see the next .json role. In env_run_lists you have _default, and we already have run_list by default. What is the difference? and will it start by default every time before starting the run_list environment?

{ "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": { } } 
+4
source share
2 answers

I agree that this is rather confusing, especially since the documentation seems to be wrong with regard to the behavior that I see when looking at the source.

From reading the source, you see that when you create the Role object, it associates the contents of the run_list attribute with _default, and then combines the hash with the contents of the env_run_lists attribute (overwriting the value for the _default key).

In practice, this means that if you specify the run_list attribute, then you do not need to include the _default environment in the env_run_list attribute. If you decide to include the _default environment in the env_run_list attribute, then it will overwrite everything that is defined in the run_list attribute.

Another obvious thing, indicating that if your node is not part of any of the environments defined in the role (_default or otherwise) it will return to using run_list for the _default environment .

+3
source

In practice, this means that if you specify the run_list attribute, you do not need to include the _default environment in the env_run_list attribute.

I don't have a reputation of 50, so I can't comment on Jared Russell's answer, but if I have this in defining my role:

 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: the _default key is required in env_run_lists.

So I had to specify the _default key in env_run_lists, even if my run_list is specified.

+2
source

Source: https://habr.com/ru/post/1487413/


All Articles