Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chef include recipes override attributes

When you include a recipe in another recipe how to do you override the attributes.

It looks the include recipe used the default attributes not the attributes of the recipe when it was run previously in the run_list.

like image 327
neill Avatar asked Mar 04 '13 15:03

neill


People also ask

Can you override attributes?

You can not override a attribute, only hide it. This is literally called hiding fields in the tutorial. More details on this blog.

What and why are Chef cookbooks and recipes used in Chef?

Cookbooks serve as the fundamental unit of configuration and policy details that Chef uses to bring a node into a specific state. This just means that Chef uses cookbooks to perform work and make sure things are as they should be on the node.


1 Answers

When you are creating a wrapper cookbook, it is common to override attributes.

Suppose, you have my_web_server cookbook with my_web_server/recipes/default.rb like this:

include_recipe "apache2"

And you would like to override attribute default_site_enabled from apache2 cookbook. Then your file my_web_server/attributes/default.rb should look like:

override['apache']['default_site_enabled'] = true

And don't forget to specify dependencies in my_web_server/metadata.rb like:

depends "apache2"
like image 182
Andriy Samilyak Avatar answered Oct 09 '22 17:10

Andriy Samilyak