As a systems administrator, automated system configuration is a gold standard. Although in some cases a bash script may do exactly what you need, once you have to manage more than one system, the single script won’t scale.
Fortunately, there are tools available to do just that. I won’t go in details explaining Puppet and Chef as there are already plenty of articles in the net. I, however, will write about my experience with them both.
Puppet and Chef are systems used for automated system configuration management, That is, you would specify which set of configuration you want deployed to a specific system and it will push the configuration to the server. Examples of configurations are set the ntp, hostnames, certain gems, apache config, mysql, adding users/passwords, etc.
Puppet and Chef require a server to host all the configuration files, the clients would then query the server asking if there’s a configuration available for them. If there is, they would auto configure according to the “recipe”
Pretty powerful, eh? As you could probably imagine, you can take this to the next level by having all your recipes stored in a revision control systems such as Git and having your systems deployed from a Virtual Host Server
Sounds all good but there’s a catch, you have yet another system to maintain. However, I’m sure the pros outweight the cons.
That said, there are some cases where having another server to maintain is too much. Welcome the world of Chef-Solo. Chef-Solo is based on Chef with the difference that you don’t need a server. It can run in a self-contained world. And if you don’t have lots of different configurations to maintain, it’s probably the right tool for the job.
In my case, all servers are deployed with a standard configuration (rvm, ruby 1.9.x, Rails, Apache/Nginx, Mysql, Ntp, Backupninja, and a few others.) Having used Puppet for at least two years, I found that, a script may be more appropriate/manageble rather than an all-out server, and that’s when I started looking into Chef-Solo.
Aside from the fact that there are plenty of community recipes for all kind of systems/software packages, it’s not hard to use/run at all.
One of the things I encountered when setting up a server is that in order for Chef-Solo to work, you have to have Ruby and Chef-Solo installed (duh!)
So when deploying a new server, all you have to do is install a flavour or ruby, I use 1.9.2, and chef.
Here’s a script I run after a machine has been deployed
# Installing git apt-get -y install git-core ## Install Chef dependencies apt-get -y install ruby ruby-dev libopenssl-ruby rdoc ri irb build-essential wget ssl-cert ruby1.8-dev ## Get latest rubygems cd /tmp wget http://production.cf.rubygems.org/rubygems/rubygems-1.7.2.tgz tar zxf rubygems-1.7.2.tgz cd rubygems-1.7.2 ruby setup.rb --no-format-executable ## Install chef solo gem install chef --no-ri --no-rdoc gem install ohai --no-ri --no-rdoc
After this you can use start using chef recipes.
For example, a very basic recipe would be to install ntp (I’m using Ubuntu 10.04)
Create a this folder structure in a folder, I’m using $HOME
mkdir -p chef-solo/config
- These two are the configuration files for chef-solo
touch config/node.json
touch config/solo.rb
cat chef-solo/config/node.json
{
“run_list”: [ “recipe[ntp]”
]
}
cat chef-solo/config/solo.rb
file_cache_path “/root/chef-solo”
cookbook_path “/root/chef-solo/cookbooks”
mkdir -p chef-solo/cookbooks/ntp/recipes
touch chef-solo/cookbooks/ntp/recipes/default.rb
#Add this to default.rb, it will add the ntp package to your installation
cat chef-solo/cookbooks/ntp/recipes/default.rb
package “ntp”
#From the chef-solo folder, run this command
chef-solo -c config/solo.rb -j config/node.json
Congrats, your system has ntp now! Very basic but sometimes that’s all you need to get started.