You are previewing Test-Driven Infrastructure with Chef.

Test-Driven Infrastructure with Chef

Cover of Test-Driven Infrastructure with Chef by Stephen Nelson-Smith Published by O'Reilly Media, Inc.
O'Reilly logo

Using Chef to Write Infrastructure Code

Now that we have Ruby and Chef installed, and are set up on the platform, we’re able to start using Chef to apply the Infrastructure as Code paradigm. Given that the whole paradigm we are discussing is about managing our infrastructure as code, our first step must be to create a repository for our work. The quickest way to do this is to clone the example Chef repository from Opscode’s GitHub account:

$ git clone

This repo contains all the directories you will work with as part of your regular workflow as an infrastructure developer. It also contains a Rakefile that handles some useful tasks, such as creating self-signed SSL certificates. In practice, though, you’re unlikely to use rake, as Knife will do more than 99% of the tasks you’ll find yourself needing to do.

Now, because we cloned this repository from GitHub, it will currently be set to fetch and pull from this example repository. We want to have and use our own repository. The simplest approach is to use GitHub, which provides limitless public repositories and offers bundles of private repositories starting from $7 a month. Alternatively, it’s not difficult to set up and run your own Git server. Although not mandatory, I recommend that you sign up for GitHub ( now (if you haven’t already), and follow the simple instructions to create a repository. Call it chef-repo to keep things simple. Once you’ve got a local copy of the Chef ...

The best content for your career. Discover unlimited learning on demand for around $1/day.