Profile Picture

Coder at Codemancers, Bangalore. GardenCityRubyConf organizer.

Works with Ruby, JS, C++, AWS, Chef and Vim.

Plays the guitar and sketches other times.

Emil Soman

Hello Chef!

I'm new to Chef. In fact the only time I was good at SysAdmin tasks was when I was 12 years old and I had a Windows 98 running on a Pentium 90 Mhz at my disposal. There was no internet - so no StackOverflow or Google. It was all self service.

Yes those were beautiful days, trying to figure out everything on my own, the sleepless nights spent tuning the hesitant old machine to run impossible things. But that doesn't mean I'm happy to spend sleepless nights at office trying to figure out dependency issues in packages when I'm a Ruby developer. There got to be better ways of doing this. Let's look at Chef.

I have a Vagrant virtual box setup on my machine. I'm thinking I'll use that as a Chef Client. I'll use my host machine as the Chef Server.

I'm following the OpsCode docs for this one

In my host, I run this :

sudo apt-get install ruby ruby-dev libopenssl-ruby rdoc ri irb build-essential wget ssl-cert rubygems
sudo gem install --no-rdoc --no-ri chef

This installs the chef-solo which I'll use to bootstrap chef-server. As it turned out, sudo was important.

Next, create /etc/chef to store configurations for chef solo runs.

sudo mkdir /etc/chef/

Create /etc/chef/solo.rb configuration file as below :

We also need a JSON file which will tell chef-solo to pick a certain list of recipes to run and specific attributes to configure on the system Create ~/chef.json configuration file as below :

Run the following to bootstrap chef-server :

sudo chef-solo -c /etc/chef/solo.rb -j ~/chef.json -r http://s3.amazonaws.com/chef-solo/bootstrap-latest.tar.gz

This installs chef-server , chef-solr , chef-server-webui and all the dependencies .

Run this to start the cef server:

sudo ln -s /usr/local/bin/chef-solr /usr/bin/chef-solr
sudo ln -s /usr/local/bin/chef-expander /usr/bin/chef-expander
sudo ln -s /usr/local/bin/chef-server /usr/bin/chef-server
sudo ln -s /usr/local/bin/chef-client /usr/bin/chef-client
sudo ln -s /usr/local/bin/chef-solo /usr/bin/chef-solo
sudo /etc/init.d/chef-solr start
sudo /etc/init.d/chef-expander start
sudo /etc/init.d/chef-server start

Chef-Server is running now. That wasn't so hard.

Now we'll create ~/.chef directory to hold the configurations for the server. We'll move the keys generated by the server to this directory and set permissions for the current user

mkdir -p ~/.chef
sudo cp /etc/chef/validation.pem /etc/chef/webui.pem ~/.chef
sudo chown -R $USER ~/.chef

The next step is to configure the knife command line tool. Let's do that :

knife configure -i
WARNING: No knife configuration file found
Where should I put the config file? [/home/emil/.chef/knife.rb] 
Please enter the chef server URL: [http://emil-desktop:4000] http://l.m.x.y:4000
Please enter a clientname for the new client: [emil] 
Please enter the existing admin clientname: [chef-webui] 
Please enter the location of the existing admin client's private key: [/etc/chef/webui.pem] .chef/webui.pem
Please enter the validation clientname: [chef-validator] 
Please enter the location of the validation key: [/etc/chef/validation.pem] .chef/validation.pem
Please enter the path to a chef repository (or leave blank): 
Creating initial API user...
Created client[emil]
Configuration file written to /home/emil/.chef/knife.rb

Running knife client list should show your username in the list .

Now as per the manual , there are a few things you have to do, if you're planning to work on the cookbooks from a different development machine (eg. Your laptop). I'm skipping these steps for now.

So that's it , chef-server is done! We'll configure the chef-client in the next post.

comments powered by Disqus