2

I'm trying to run the open-source Java cookbook using chef-solo and although it shouldn't require any other cookbooks, chef keeps saying that a cookbook required to run this one is missing. First it asked me to install apt, then homebrew, then _build_essentials_. It seems like a never ending list of cookbooks. What am I doing wrong?

This is how I'm running the cookbook:

chef-solo -c solo.rb -o recipe[java] 

Where solo.rb is a configuration file with the path to the cookbooks folder.

The same thing also happens when I try to run the WAS cookbook.

StephenKing
  • 36,187
  • 11
  • 83
  • 112
ninesalt
  • 4,054
  • 5
  • 35
  • 75

1 Answers1

1

In short: Chef does not (yet) support conditional dependencies. That's why all cookbooks that provide resources or recipes that might be used need to be declared as dependency.

The Java cookbook uses resources from many other cookbooks to install Java on different systems, e.g., Windows, Linux, MacOS etc. Therefore, it makes use of other cookbooks, that provide resources for e.g. installing a package under Windows, adding an APT repository etc.

In order to allow the cookbook to either include a recipe or use a resource (e.g. apt_repository) from another cookbook, this one has to be specified as dependency so that it is loaded prior to executing the cookbook (e.g. Java). Otherwise, this resource/recipe would not be known to Chef.

So all of these cookbooks will be loaded during the Chef run, but their code will not be executed. While this feels a bit annoying, esp. in your case when you obviously manually download the cookbooks, this isn't so disturbing when you use Berkshelf for dependency resolution. This is highly recommended.

StephenKing
  • 36,187
  • 11
  • 83
  • 112
  • This looks promising. Would I still have to write "depends 'cookbookname' " in the metadata.rb file for all the downloaded cookbooks? I used berkshelf to download the dependant cookbooks but it still says they're missing when I try to run the original cookbook. – ninesalt Jul 24 '16 at 09:25
  • If you want to use the Java cookbook and use Berkshelf to download dependencies, you shouldn't have to change anything. Probably, Chef Solo doesn't pick up your cookbooks. I don't remember exactly, if you have to configure some cookbook path or not. Haven't used that for years. – StephenKing Jul 24 '16 at 09:32
  • Do you have any idea where the cookbooks are installed? I cant find them and I cant find anything in the documentation that says where they are installed. Thanks for the help by they way! – ninesalt Jul 24 '16 at 09:43
  • IIRC either you use `berks vendor` and your cookbooks end up in `vendor/cookbooks` (?), or you run `berks install` and your cookbooks end up in `~/.berkshelf/cookbooks`. Not sure, if `chef-solo` will pick them up automatically from both locations. – StephenKing Jul 24 '16 at 09:44
  • @Swailem95 Last option is berks package which will make a tarball with all needed cookbooks, then you set it on a http server or your push it to your node and you give the url (http:// or file://) to this tarball to chef-solo with --recipe-url and all should be ok (with a correct runlist) – Tensibai Jul 25 '16 at 15:27