Codular

HomeWriters RSS

What are Chef Cookbooks?

Introduction

Automating as much process as possible is vital in the modern day to allow developers the ability to get down to the nitty-gritty more quickly. Removing as many barriers as possible for developers is key, and using a standard provisioning method helps with this. For example ensuring that your production, staging and development environments are all the same will remove the "works on my machine" argument that sometimes crops up.

There are many options available for provisioning, however Chef tends to be one of the more widly used options, especially within the enterprise space. Even AWS has support for Chef based provisioning built in.

Getting Started

Chef Cookbooks are mostly built around their "Supermarket", which is basically a list of all of the cookbooks that are available that you can use. Many are configurable by passing in different parameters within the Node's JSON configuration file. Cookbooks are made up of Recipes which define what commands to run etc, and are written in Ruby.

Cookbook Structure

The structure and configuration of the cookbook directory is defined as below, with key bits of information required for the successful run.

- README.md
- attributes
-- default.rb
- libraries
-- helpers.rb
- metadata.rb
- recipes
-- default.rb

metadata.rb

Here is an example of the metadata that you could use for a new cookbook clearly defining many of the settings.

name             'cookbook_codular'
maintainer       'Michael Wright'
maintainer_email 'contact@codular.com'
license          'Apache 2.0'
description      'Codular cookbook.'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version          '0.0.1'

recipe 'cookbook_codular', 'Codular Cookbook'

%w{ ubuntu }.each do |os|
  supports os
end

%w{ cookbooks_here }.each do |cb|
  depends cb
end

Next Steps

This is a very brief outline of what a cookbook is, and how they are structured. There are plenty of examples available to take a look through, to get an understanding.

In the next step we'll look at creating our own Cookbook and following through the process of then tying that into Vagrant and getting it up and running.