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 http://github.com/opscode/chef-repo.git

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 (http://github.com) 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 ...

Get Test-Driven Infrastructure with Chef 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.