AddingAChefCookbook - noahgibbs/madscience GitHub Wiki

Adding an Existing Chef Cookbook

Chef cookbooks often have recipes, which can be included by just adding them to the runlist and, if necessary, adding a block of config information for them.

If the cookbook needs attributes set like node['mysql']['server_root_password'], those go in the node's JSON file (like app-server.json.erb) directly. You can find the attributes in the cookbook's documentation, or by reading through the source, especially cookbook_name/attributes/default.rb.

Adding a New Custom Chef Cookbook

To do this, you'll need to write a cookbook. There's lots of good documentation online, and you can start by renaming an existing cookbook. A minimal cookbook may have only a metadata.rb file and one recipe.

The easiest way to include a new custom cookbook is to put that cookbook under the 'site-cookbooks' directory of your deploy repo. You can also publish your cookbook (very much like a gem) and just include it in your runlist -- the Cheffile will parse the JSON file's runlist and include any cookbooks mentioned.

Chef Versions

Older Chef cookbooks, especially version 10 and earlier, may not be compatible with Chef 12.0.3 used in current MadScience deploys. In general, contact the author about upgrading the cookbook, or look for a cookbook that is currently maintained.

You can also see if the problem is easy to fix, as many are. The author might accept a pull request, or you can copy the cookbook into site-cookbooks and just make the fix locally. That's usually a good idea while waiting for the pull request to be accepted, too.

If necessary you can write your own -- writing one that serves just your own need may be a lot easier than patching a more general cookbook. In that case, definitely put it under site-cookbooks as a custom cookbook.