Chef-Solo – How to run a cookbook

*requires: base installation of debian or ubuntu

Install Ruby and Chef

Ubuntu:

$ apt-get install ruby1.9.1 rubygems1.9.1 chef git -y

Debian:

$ echo "gem: --bindir=/usr/bin --no-ri --no-rdoc" >> /etc/gemrc
$ apt-get install ruby1.9.1 rubygems1.8 git-core -y >> gem install chef
$ echo "PATH=\$PATH:$GEMDIR" >> ~/.bashrc

Create your cookbook directory and copy cookbooks into it

$ mkdir -p /root/chef-solo/cookbooks && cd /root/chef-solo/cookbooks
$ git clone https://github.com/opscode-cookbooks/ntp.git

Create “solo.rb”

$ cat>solo.rb<<EOF
file_cache_path "/root/chef-solo"
cookbook_path "/root/chef-solo/cookbooks"
EOF

Create “solo.json”

$ cat>solo.json<<EOF
{
  "run_list": [ "recipe[ntp::default]" ]
}
EOF

Run Chef Solo

$ chef-solo -c solo.rb -j solo.json
Example output:
[Sat, 23 Jun 2012 03:03:58 +0000] INFO: *** Chef 10.12.0 ***
[Sat, 23 Jun 2012 03:03:58 +0000] INFO: Setting the run_list to ["recipe[ntp::default]"] from JSON
[Sat, 23 Jun 2012 03:03:58 +0000] INFO: Run List is 
] [Sat, 23 Jun 2012 03:03:58 +0000] INFO: Run List expands to [ntp::default] [Sat, 23 Jun 2012 03:03:58 +0000] INFO: Starting Chef Run for ubuntu01.home [Sat, 23 Jun 2012 03:03:58 +0000] INFO: Running start handlers [Sat, 23 Jun 2012 03:03:58 +0000] INFO: Start handlers complete. [Sat, 23 Jun 2012 03:03:58 +0000] INFO: Processing package[ntpdate] action install (ntp::default line 24) [Sat, 23 Jun 2012 03:03:58 +0000] INFO: Processing template[/etc/default/ntpdate] action create (ntp::default line 28) [Sat, 23 Jun 2012 03:03:58 +0000] INFO: template[/etc/default/ntpdate] backed up to /var/chef/backup/etc/default/ntpdate.chef-20120623030358 [Sat, 23 Jun 2012 03:03:58 +0000] INFO: template[/etc/default/ntpdate] mode changed to 644 [Sat, 23 Jun 2012 03:03:58 +0000] INFO: template[/etc/default/ntpdate] updated content [Sat, 23 Jun 2012 03:03:58 +0000] INFO: Processing package[ntp] action install (ntp::default line 35) [Sat, 23 Jun 2012 03:04:09 +0000] INFO: package[ntp] installed version 1:4.2.6.p3+dfsg-1ubuntu3.1 [Sat, 23 Jun 2012 03:04:09 +0000] INFO: Processing directory[/var/log/ntpstats/] action create (ntp::default line 57) [Sat, 23 Jun 2012 03:04:09 +0000] INFO: Processing service[ntp] action enable (ntp::default line 64) [Sat, 23 Jun 2012 03:04:09 +0000] INFO: Processing service[ntp] action start (ntp::default line 64) [Sat, 23 Jun 2012 03:04:09 +0000] INFO: Processing template[/etc/ntp.conf] action create (ntp::default line 69) [Sat, 23 Jun 2012 03:04:09 +0000] INFO: template[/etc/ntp.conf] backed up to /var/chef/backup/etc/ntp.conf.chef-20120623030409 [Sat, 23 Jun 2012 03:04:09 +0000] INFO: template[/etc/ntp.conf] mode changed to 644 [Sat, 23 Jun 2012 03:04:09 +0000] INFO: template[/etc/ntp.conf] updated content [Sat, 23 Jun 2012 03:04:09 +0000] INFO: template[/etc/ntp.conf] sending restart action to service[ntp] (delayed) [Sat, 23 Jun 2012 03:04:09 +0000] INFO: Processing service[ntp] action restart (ntp::default line 64) [Sat, 23 Jun 2012 03:04:11 +0000] INFO: service[ntp] restarted [Sat, 23 Jun 2012 03:04:11 +0000] INFO: Chef Run complete in 12.81987 seconds [Sat, 23 Jun 2012 03:04:11 +0000] INFO: Running report handlers [Sat, 23 Jun 2012 03:04:11 +0000] INFO: Report handlers complete