Tag Archives: littlechef

LittleChef: playing with Chef recipes

For small number of servers and push deployment, I show how to run LittleChef here:

Using RVM for Ruby needed for Chef’s knife later.

ubuntu@testbox:~/littlechef$ rvm use 1.9.2

Using virtrualenv for Python, so as not to clutter environment’s Python installation.
Genenerate metadata.json for Chef recipes.

ubuntu@testbox:~/littlechef$ workon lchef
ubuntu@testbox:~/littlechef$ cd kitchen/cookbooks
(lchef)ubuntu@testbox:~/littlechef/kitchen/cookbooks$ knife cookbook metadata -a  -o ./
Generating metadata for alestic_ppa from /home/ubuntu/littlechef/kitchen/cookbooks/alestic_ppa/metadata.rb
Generating metadata for apt from /home/ubuntu/littlechef/kitchen/cookbooks/apt/metadata.rb
Generating metadata for graylog2 from /home/ubuntu/littlechef/kitchen/cookbooks/graylog2/metadata.rb
Generating metadata for java from /home/ubuntu/littlechef/kitchen/cookbooks/java/metadata.rb
Generating metadata for java_sun from /home/ubuntu/littlechef/kitchen/cookbooks/java_sun/metadata.rb
Generating metadata for logrotate from /home/ubuntu/littlechef/kitchen/cookbooks/logrotate/metadata.rb
Generating metadata for mdadm from /home/ubuntu/littlechef/kitchen/cookbooks/mdadm/metadata.rb
Generating metadata for memcached from /home/ubuntu/littlechef/kitchen/cookbooks/memcached/metadata.rb
Generating metadata for mongodb from /home/ubuntu/littlechef/kitchen/cookbooks/mongodb/metadata.rb
Generating metadata for mongodbx from /home/ubuntu/littlechef/kitchen/cookbooks/mongodbx/metadata.rb
Generating metadata for nginx from /home/ubuntu/littlechef/kitchen/cookbooks/nginx/metadata.rb
Generating metadata for quick_start from /home/ubuntu/littlechef/kitchen/cookbooks/quick_start/metadata.rb
Generating metadata for runit from /home/ubuntu/littlechef/kitchen/cookbooks/runit/metadata.rb
Generating metadata for xfs from /home/ubuntu/littlechef/kitchen/cookbooks/xfs/metadata.rb

List nodes using LittleChef:

(lchef)ubuntu@testbox:~/littlechef/$ fix list_nodes
ec2-xx-xx-xxx-xxx.compute-1.amazonaws.com
  Roles: 
  Recipes: alestic_ppa
  Node attributes:

server2
  Roles: 
  Recipes: mdadm, memcached
  Node attributes:
    mdadm: {'DEVICE': '/dev/sdj'}
    memcached: {'memory': '512'}

List of files on my kichen directory:

 
(lchef)ubuntu@testbox:~/littlechef/kitchen$ ls
auth.cfg  cookbooks  data_bags  nodes  roles  site-cookbooks

(lchef)ubuntu@testbox:~/littlechef/kitchen$ ls cookbooks/
alestic_ppa  apt  graylog2  java  java_sun  logrotate  mdadm  memcached  mongodb  mongodbx  nginx  quick_start  README  runit  xfs
 

Ok, let’s run the nginx installation using LittleChef to lucid32 server.
For simplicity, /etc/hosts file contains the IP mapping of lucid32 server.

(lchef)ubuntu@testbox:~/littlechef/kitchen$ fix node:lucid32 recipe:nginx

== Applying recipe 'nginx' on node lucid32 ==
Saving node configuration to nodes/lucid32.json...
Synchronizing node, cookbooks, roles and data bags...
ubuntu@lucid32's password: 

Cooking...
[Mon, 06 Feb 2012 23:13:40 -0800] INFO: *** Chef 0.10.8 ***
[Mon, 06 Feb 2012 23:13:40 -0800] INFO: Setting the run_list to ["recipe[nginx]"] from JSON
[Mon, 06 Feb 2012 23:13:40 -0800] INFO: Run List is [recipe[nginx]]
[Mon, 06 Feb 2012 23:13:40 -0800] INFO: Run List expands to [nginx]
[Mon, 06 Feb 2012 23:13:40 -0800] INFO: Starting Chef Run for lucid32
[Mon, 06 Feb 2012 23:13:40 -0800] INFO: Running start handlers
[Mon, 06 Feb 2012 23:13:40 -0800] INFO: Start handlers complete.
[Mon, 06 Feb 2012 23:13:41 -0800] INFO: execute[apt-get update] sh(apt-get update)
[Mon, 06 Feb 2012 23:13:44 -0800] INFO: execute[apt-get update] ran successfully
[Mon, 06 Feb 2012 23:13:44 -0800] INFO: directory[/var/cache/local] mode changed to 755
[Mon, 06 Feb 2012 23:13:44 -0800] INFO: Chef Run complete in 4.193466 seconds
[Mon, 06 Feb 2012 23:13:44 -0800] INFO: Running report handlers
[Mon, 06 Feb 2012 23:13:44 -0800] INFO: Report handlers complete

SUCCESS: Node correctly configured

Done.
Disconnecting from lucid32... done.

Now to check for the running Nginx server:

(lchef)ubuntu@testbox:~/littlechef/kitchen$ fix node:lucid32 ssh:"sudo netstat -lp | grep nginx "

Executing the command 'sudo netstat -lp | grep nginx ' on the node lucid32...
tcp        0      0 *:www                   *:*                     LISTEN      814/nginx       

Done.
Disconnecting from lucid32... done.

LittleChef to use SSH keypair

I found out littlechef from Grig’s post. Thanks to both Grig and to Miguel for the tool and good writeup.

I added some lines to work with the new feature of littlechef about the SSH keypair. Now I can login to my Ubuntu Amazon EC2 instances by specifying the keypair-path on the auth.conf:

[userinfo]
user = ubuntu
password = 
keypair-file =  /home/cocoy/.ssh/id-rsa.pub

Hope that works well for others. The gist is shown below: