Question

I've created a chef cookbook, which has lot's of dependencies to other cookbooks. My main problem now is that the recipes from other cookbooks are executed in the random order. If I specify the execution of these recipes in the vagrant file like:

chef.add_recipe "gitlab::core_prereq"
chef.add_recipe "postfix"
chef.add_recipe "gitlab::users_prereq"
chef.add_recipe "rvm::vagrant"
chef.add_recipe "rvm::system"
chef.add_recipe "ohai"
chef.add_recipe "nginx"
chef.add_recipe "gitlab::python_tools_prereq"
chef.add_recipe "gitlab::gitolite_prereq"
chef.add_recipe "gitlab::gitlab_install"

Everything works fine, but I would like to have this spec in the recipe, so that a user just needs to include the default recipe and gets everything needed installed in the right order.

How can I solve this? Should I use a role? I don't get it from the chef docs, if the role can be specified within a recipe.

Was it helpful?

Solution

I guess not all of your recipes can be installed on clean machine. But they should be. If some recipe "A" has some prerequisitives, then you should add that required recipes into recipe "A" using include_recipe.

In your case I guess that gitlab::gitlab_install requires gitlab::gitolite_prereq and gitlab::python_tools_prereq. That means you should add to your cookbooks/gitlab/recipes/gitlab_install.rb:

incude_recipe 'gitlab::gitolite_prereq'
incude_recipe 'gitlab::python_tools_prereq'

You can also include recipes from other cookbookss this way. For exampple ohai requires rvm::system. Add to cookbooks/ohai/recipes/default.rb:

incude_recipe 'rvm::system'

and add to cookbooks/ohai/metadata.rb:

depends 'rvm'

This way you will not have to write all the recipes in some exact order, and you don't have to write all the dependencies, they will be installed automatically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top