Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use include_recipe or add the recipe to run_list?

Trying to figure out the best approach for a large project. When is it appropriate to add recipes within a recipe by using include_recipe as opposed to adding the recipe to the run_list? Is there a good rule of thumb?

like image 443
Micah Avatar asked Jun 05 '13 18:06

Micah


People also ask

What is cookbook and recipe in Chef?

Cookbooks are fundamental working units of Chef, which consists of all the details related to working units, having the capability to modify configuration and the state of any system configured as a node on Chef infrastructure. Cookbooks can perform multiple tasks.

What is the recipe in Chef tool?

A recipe is basically a collection of resource definitions that will create a step-by-step set of instructions to be executed by the nodes. These resource definitions can be mixed with Ruby code for more flexibility and modularity.

How do you run multiple recipes in Chef?

Where we mentioned the recipes we called Run List. Run the recipes in a sequence order that we mentioned in Run List. To apply each recipe from each cookbook (not multiple recipes from same cookbook) at a time by using chef-client. To run the command be inside the cookbooks.

How do I remove a Runlist from my cookbook?

Use the run_list remove argument to remove run-list items (roles or recipes) from a node. A recipe must be in one of the following formats: fully qualified, cookbook, or default. Both roles and recipes must be in quotes, for example: 'role[ROLE_NAME]' or 'recipe[COOKBOOK::RECIPE_NAME]' .


2 Answers

As I see it, any recipe should be able to run on an empty machine on its own. So if some recipe A depends on recipe B run before it, I always use include_recipe.

For example: 2 cookbooks, tomcat and java. Tomcat requires java.

  1. When some user wants to install tomcat, he may have no idea that he actually requires some other cookbook to install it. He runs the tomcat recipe and either it fails with some completely unhelpful error message like "No java found" or even worse - it succeeds, but then of course the user cannot start tomcat, because he does not have java installed.

  2. But when there is a include_recipe 'java' line in tomcat cookbook, which also requires a depends 'java' line in metadata, the user when trying to install tomcat, will see the understandable error message: "the cookbook java not found". This way actually user can download dependencies on his own (or even with some automatic tool) without actually running recipes, but reading metadata.

like image 110
Draco Ater Avatar answered Oct 02 '22 10:10

Draco Ater


All logic should be controlled with run lists. Cookbooks, try as they might, are not as re-usable as people would like to think. All include_recipe does is add another place where users have to look to figure out what the run list is going to do so make it explicit and put it in the run list.

like image 37
David K. Avatar answered Oct 02 '22 11:10

David K.