Chef Cookbook Authoring Best Practices

Hello Young Culinarians,

I would like to share some best practices for authoring chef cookbooks.
First we are going to start with two important points when it comes to authoring effective and good cookbooks:

  • Cookbooks must be usable through being a single instance in a run list. That means reasonable(modest) use of include_recipe and cookbook dependencies.

  • Cookbooks must not require attributes to be set outside of the cookbook itself to function.

Roles, they are not bad unless you don't keep them thin... Roles that are basically nothing but a name and an attached run list are where the sweet spot is :

  • Roles should be thin by design - a run list and a name.

  • Roles should only include attributes if its unavoidably necessary.

About rolling change out across your infrastructure.. Avoid finding yourself trying to model those transitions as roles at all costs. You have two more tools in your knife set that should be what you utilize here:

  • Cookbook version equality pins used judiciously in all your environments.

  • Conditional statements in cookbooks/attributes that model the various states your
    infrastructure must be in if you can't get it done with version constraints.

Happy Hacking :)