Anuj Balan
Anuj Balan

Reputation: 7729

Recipe files included in a cookbook are not getting picked up when running Chef Client

In a cookbook, default.rb is the file which will be picked/executed. I added service.rb in the same folder cookbooks/cookbook_main/recipes folder, in which default.rb resides. I then uploaded the cookbook and executed the chef-client on a remote VM which acts as a node.

Logs showed that it detected both the rb files under recipes folder. Here is the problem, Script present in default.rb was executed but not the one in service.rb. Why?

PS: (New to Chef, so please correct if am wrong !)

Upvotes: 0

Views: 897

Answers (1)

Sneal
Sneal

Reputation: 2586

Since you only have cookbook_main in your run_list like so:

chef.add_recipe "cookbook_main"

When you only have the cookbook specified in your run list without specifying a recipe, Chef will only run the default recipe. For example, these two lines are essentially equivalent:

chef.add_recipe "cookbook_main"
chef.add_recipe "cookbook_main::default"

If you want to run the new service recipe you need to tell Chef to run it. There are a couple of ways to do this. One is to explicitly add it to your run list in your Vagrantfile:

chef.add_recipe "cookbook_main"
chef.add_recipe "cookbook_main::service"

Otherwise you can include it via your default recipe. So add this line somewhere in your default.rb recipe:

include_recipe 'cookbook_main::service'

Upvotes: 2

Related Questions