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.
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.
Let's see how to create and use a definition:
Create a definition in a new file in your cookbook's
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 "#...