Book Image

Chef Infrastructure Automation Cookbook

By : Matthias Marschall
Book Image

Chef Infrastructure Automation Cookbook

By: Matthias Marschall

Overview of this book

Table of Contents (14 chapters)
Chef Infrastructure Automation Cookbook Second Edition
About the Author
About the Reviewers

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 definitions folder:

    mma@laptop:~/chef-repo $ mkdir -p cookbooks/my_cookbook/definitions
    mma@laptop:~/chef-repo $ subl cookbooks/my_cookbook/definitions/capistrano_deploy_dirs.rb
    define :capistrano_deploy_dirs, :deploy_to => '' do
      directory "#...