Oliver Hankeln

4 minute read

I just came back from a chef fundamentals training in Gent held by @jtimberman and organized by @patrickdebois and I am even more excited about configuration management with chef than I was before.Unfortunately the documentation is a bit overwhelming at first, so I put together this small tutorial of how to setup chef on a Ubuntu 10.10 machine. Chef runs on a variety of systems, and the overall process is the same everywhere, though.

How does the chef infrastructure look like?

There are three components in the architecture:

  • your workstation, the place where you are going to develop the configuration files
  • the chef server, the configuration files are stored here. We will use the opscode platform, but it is also possible to host your own chef-server
  • the nodes, these are the machines you are going to configure with chef – they will fetch their configuration files from the chef-server

Chef uses a simply client server architecture. You create a description of your configuration and send this to a chef-server. The nodes then fetch their configuration from this chef-server and take the appropriate action.

In this tutorial you will learn of how to setup your workstation to start writing configuration scripts (they are called recipes and stored in cookbooks).

Installing Ruby and the necessary gems

First and foremost: you may have seen that there are chef packages available in Ubuntu. Do not use these packages – they are outdated and won’t work with the opscode platform anymore.

Okay, let’s get going: Chef is written in ruby, so we need to get that installed. I am not a ruby developer, so I can live with the ruby 1.8 package and will use it here. $ sudo bash # apt-get install ruby1.8 ruby1.8-dev ruby rubygems1.8 # gem install net-ssh-multi chef

If you want to use virtual servers in the cloud (and I bet you do!) you need the fog gem as well. However the current fog gem has changed its API a bit and throws a warning if used with knife, the chef command line tool. You can either ignore this warning (knife will work nevertheless) or you install an older version of the fog gem. I don’t want to get strange warnings so I chose the old fog version:

# apt-get install libxslt-dev libxml2-dev # gem install fog -v 0.2.30

Chef cookbooks and recipes are managed with git, so let’s install git and get an initial setup:

# apt-get install git # exit $ cd $ git clone git://github.com/opscode/chef-repo.git

You now have a directory chef-repo in your home directory, where you are going to do all your development.

Unfortunately the Ubuntu maintainers chose to put the gems in a place that lies outside the path, so we need to put the gems bin directory there. $ export PATH=$PATH:/var/lib/gems/1.8/bin

Please make sure that you put this in whatever startup script you use (probably ~/.profile).

Configuring knife

I have good news: You should now have chef installed successfully on your workstation. Let’s move on to configuring it.

We are going to use the opscode platform as chef server so you should create an account there. This account will be free for up to 5 managed hosts, which should be enough to do some testing. After you log in please click on „organizations“ and create a new organisation. Note that the organisation’s short name needs to be unique for the whole opscode platform. Once you have created your org you will be able to download the validation key (ignore the warning that this will invalidate your old key) and a file called knife.rb. Then click on your username and request a new private key. Put these three files in a directory .chef in your ~/chef-repo:

$ mkdir ~/chef-repo/.chef $ mv ~/Downloads/knife.rb ~/chef-repo/.chef $ mv ~/Downloads/ORGNAME-validator.pem ~/chef-repo/.chef $ mv ~/Downloads/USERNAME.pem ~/chef-repo/.chef

Make sure to replace ORGNAME with the short name of your organisation. USERNAME will be your username.

Testing the setup

Now test your configuration: $ knife node list You should see: [ ]

This is the list of your nodes. You haven’t added nodes so this is empty.

Great! You are now set and can start working with chef! In the next part of this series I will show how to set up a simple webserver on an ec2 instance with chef. Stay tuned!

comments powered by Disqus