My (very) personal chef tutorial Part I: Setup and recipes

Since I have been working with chef for some time, I decided to create a little tutorial to record my experiences.

Note that I am neither a chef nor a ruby expert, so forgive me if I do not always use the absolutely best approach.

The first part of this tutorial covers setting up a cookbook and running a simple recipe. I suggest downloading the source code for the example from the git repository. You will find all files used throughout this example in the folder cookbooks/chef-examples. Enjoy!

In order to quickly create a cookbook use the knife command:

This command creates a subdirectory cheftutorial in the current directory that contains the most essential files for a cookbook. Let’s look at what has been created:

All lot of stuff created for a simple cookbook. Let’s start going through the individual elements.


All the recipes are to be placed here. Here is the content of a simple recipe in the file welcome.rb that logs a message.

This recipe welcomes the user that is currently logged in. To run the recipe simply use chef-apply as follows in the cookbooks folder:

chef-apply is fast and ideal to tests recipes against the local machine outside of the context of the cookbook. The output of running this command looks like this:

Per default a recipe called default.rb is created in the folder recipes, which is by convention run, when no other recipe is specified. So it is a good starting point for writing own recipes.

That wasn’t to hard. Is suggest experimenting a little bit with your own recipes just to get familiar with them. In the second part of my tutorial we will look at using attributes.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">