include_recipe vs vagrantfile chef.add_recipe Who cares?

Just ran nginx :: source recipe on my stray field and I have very unusual behavior.

When I include a recipe from Vagrantfile (as shown below), everything works like a charm,

chef.add_recipe ("Project :: Nginx")
chef.add_recipe ("Nginx :: source")

(project :: nginx recipe is very simple. Using it to override the default attributes for the nginx cookbook)

but if I include the recipe at the very end of the project :: nginx (mentioned above), everything will fall apart:

node.default['nginx']['server_names_hash_bucket_size'] = 128 include_recipe "nginx::source" 

Until now, I did not know what the difference in behavior is between these two challenges. Does anyone know what the difference is?

+6
source share
1 answer

Gotya! Chef 11. The problem with him exists only in chef-solo :)

To make a quick resume, the difference is:

  • chef.add_recipe () - loads the entire cookbook context (all files, for example, recipes, definitions, attributes ...)
  • include_recipe "" - files (attributes, definitions, etc.) that are not included in the extended launch list are not loaded.

There are at least 4 ways to solve the problem (put the files on the launch list):

  • include_attribute - explicitly specify the desired attribute file.
  • metadata.rb-> dependency - if your cookbook uses a recipe from another cookbook, put this cookbook in the metadata.rb dependency section and upload all its files.
  • chef.add_recipe () - Download the recipe via Vagrantfile. (Mentioned here for reference only)
  • Berkshelf - you can use this cookbook manager to solve this problem. Here's fooobar.com/questions/959277 / ... and a few Docs

For those interested in further reading, Chef 11 introduced a dependency-based cookbook download for non-recipe files. The new loading logic means that files belonging to cookbooks that exist in cookbook_path but are not in the extended run_list, or cookbook dependencies in the extended run_list will no longer be loaded. REF: Opscode violates the documentation of the changes , and if you need the error signature I received, it is exactly the same here, even for the same reason.

+9
source

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


All Articles