Technology Inside Out!

Index ¦ Archives ¦ Atom ¦ RSS

Getting Started With Chef-solo


Chef is an amazing tool from opscode to automate your work. Though it is very useful, it is also very complex to understand and work with. Before discussing about Chef-solo, here are some terminologies related to chef that we should learn first.

Recipes: These are the files that contain the configuration. Simply, these files have the code that is going to be used to configure your server.

Cookbooks: A collection of recipes is called a cookbook.

Chef-client: A tool which runs on the server that is supposed to be configured by chef.

Chef-server: This is the server that provides cookbooks/recipes to chef-client.

Chef-solo: An independent chef configuration tool that doesn’t need chef-server to work.

Chef-solo is the easiest way to learn how chef works. In this article we will see the working of chef-solo with an example. The first step is to install chef. Chef is installed as a rubygem. So, install rubygem and chef using following commands. (I am using Fedora. Use sudo apt-get for debain based systems.)

$ sudo yum install ruby rubygems ruby-devel

$ gem install chef

You can check if your installation was successful or not by running ‘chef-solo’ command as sudo/root. It will most probably give an error “No cookbook found”. That’s alright, if you are getting any other error, then you need to check the installation again. So, now we are going to write a recipe to print “Hello chef” on the command prompt.

First of all, make a directory where you are going to do all your work. Let’s call it chef.

# mkdir chef

Now, we need to make the recipe. Let’s call the recipe hellochef. Here is how you can create it:

Now write the line ‘puts “Hello Chef!” ‘ in the file default.rb and close it. It is a ruby file, so it’s better you make yourself familiar with ruby before moving ahead with chef. Now that we have our recipe, next step is to redirect chef-solo to our recipe. We need to tell chef-solo that which cookbook we want to run. To do that create a node.json inside chef/ directory and put the recipe info inside it.

Save and close the file. Now, you just need one more thing, that is chef-solo configuration file. Come back to your home directory and open a file named solo.rb and write the following info in the file:

Remember to change the locations of files relative to your system! Save and close the file. Now, we are ready to run chef-solo. Run 'chef-solo -c solo.rb' from command line and you should get an output like this:

The -c option tells chef-solo about the location of the solo.rb configuration file. You can do a lot more with chef-solo than just printing Hello chef! This will get you started. Happy cooking!

© The Geeky Way. Built using Pelican. Theme by Giulio Fidente on github.

Disclaimer Privacy policy