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 !)
答案 0 :(得分:2)
由于您的run_list中只有cookbook_main
,所以:
chef.add_recipe "cookbook_main"
如果您只在运行列表中指定了食谱而未指定食谱,则Chef将仅运行默认食谱。例如,这两行基本相同:
chef.add_recipe "cookbook_main"
chef.add_recipe "cookbook_main::default"
如果您想运行新的服务配方,您需要告诉Chef运行它。有几种方法可以做到这一点。一种是将其显式添加到Vagrantfile中的运行列表中:
chef.add_recipe "cookbook_main"
chef.add_recipe "cookbook_main::service"
否则您可以通过默认配方包含它。因此,在default.rb配方中的某处添加此行:
include_recipe 'cookbook_main::service'