Should I use include_recipe or add the recipe to run_list?

旧时模样 提交于 2020-01-30 14:18:28

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/16947393/should-i-use-include-recipe-or-add-the-recipe-to-run-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!