Using definitions

Your cookbooks will grow and get pretty long. Silently, some duplication will sneak in, as well. It's time to group resources and give them names in order to regain readability for your cookbook. Also, if you use the same set of resources again and again, it is a good idea to refactor such groups of resources into definitions.

In this section, we'll group a set of resources into a definition to make it reusable.

Getting ready

Make sure you have a cookbook called my_cookbook and that the run_list file of your node includes my_cookbook, as described in Creating and using cookbooks recipe of Chapter 1, Chef Infrastructure.

How to do it...

Let's see how to create and use a definition:

  1. Create a definition in a new file in your cookbook's ...

Get Chef: Powerful Infrastructure Automation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.