What’s the difference between Chef Cookbooks and Chef Roles

chef

My current understanding:

  • You can add a recipe to a client. A recipe can contain other recipes.
  • You can add a role to a client. A role can contain other roles and recipes.

Then what's the practical difference between a recipe and a role? Why would I want to make a role consisting of multiple recipes instead of just a recipe consisting of multiple recipes?

Best Answer

The only major, practical differences are that roles can't be versioned, and it's easier to search for Chef nodes in a role than Chef nodes that ran a recipe. They're intended to be a lightweight way to group servers that shouldn't contain much business logic. Many implementations eschew roles completely in favor of 'role books' -- basically cookbooks written to behave like roles.

These are two of my favorite posts that cover the topic:

http://realityforge.org/code/2012/11/19/role-cookbooks-and-wrapper-cookbooks.html

https://web.archive.org/web/20160310031442/http://dougireton.com/blog/2013/02/16/chef-cookbook-anti-patterns/

Related Topic