CNK's blog

Chef Quick Start

So I have been fooling with chef for nearly a year now - including going to an Opscode workshop before Rocky Mountain Ruby - but I haven’t really gotten over the hump into using it for real. But I think it’s time.

So starting with the Quick Start guide on LearnChef, I set up my laptop as the workstation. My default ruby under RVM is currently 2.0.0-p353. I created a gemst called chef and installed the chef gem (current version is 11.8.2). During the Chef workshop we all signed up for the free hosted chef server, so I have a login (ckiser) and organization (ckiser) already. I downloaded the starter kit. (It warned me that it would reset my user and organization keys but that’s probably fine.) I moved the chef-repo directory into my home directory. The README said that stuff there should be under version control, so I did git init and committed all the files before starting.

Chef Quick Start - with Vagrant and Chef Server

First off, we installed 2 cookbooks from the Opscode community site, apt and apache2, with knife cookbook site install [repo]. I am a little unclear on what ‘site’ means in that command but anyway, that command created 2 new directories in my cookbooks directory. Then we created our own cookbook. First we installed a dependency, magic_shell. Then we generated the cookbook: knife cookbook create aliases, added the dependency line in the metadata.rb file, and then edited the default recipe. The tutorial then told us to upload the cookbooks to our hosted chef using knife cookbook upload --all. It uploaded all the cookbooks - the ones we got from the community site and the aliases cookbook we just made - and all without our having to commit them to git.

But I do have one mystery. The cookbooks we installed using knife cookbook site install [some repo] do not show up as untracked files for git - but the aliases cookbook we just created ourselves does. I don’t see anything obvious like mentions of the community cookbooks in a .gitignore or .chefignore file. So how does git know the difference?

# Untracked files:
#       cookbooks/aliases/

Then the guide had us boot a VM from the Vagrant file that came with the starter kit - using an Ubuntu image we downloaded from OpsCode. The file name,, makes me think that it doesn’t have chef installed, nor any other ruby. When I did the initialization that the guide suggested, I see output that appears to first install chef from OpsCode’s s3 stash:

~/chef-repo) $ knife bootstrap localhost --ssh-user vagrant \
                                         --ssh-password vagrant \ 
                                         --ssh-port--2222 \
                                         --run-list "recipe[apt],recipe[aliases],recipe[apache2]" 

localhost Downloading Chef 11.8.2 for ubuntu...
localhost downloading
localhost   to file /tmp/
localhost trying wget...
localhost url
localhost Installing Chef 11.8.2
localhost installing with dpkg...
localhost Selecting previously unselected package chef.
localhost Unpacking chef (from .../chef_11.8.2_i386.deb) ...
localhost Setting up chef (11.8.2-1.ubuntu.12.04) ...
localhost Thank you for installing Chef!
localhost Starting Chef Client, version 11.8.2
localhost Creating a new client identity for ckiser-starter using the validator key.
localhost resolving cookbooks for run list: ["apt", "aliases", "apache2"]
localhost Synchronizing Cookbooks:..

Hmmm so perhaps I don’t have to preinstall ruby and chef. The bootstrap process can install the latest version of chef (11.8.2) packaged with an up to date ruby, ruby 1.9.3p484 (2013-11-22 revision 43786) in /opt/chef/embedded/bin/ruby.

Also note that the bootstrap command, after installing chef, registered the node we are operating on with my hosted chef server. The name, ckiser-starter, appears to come from the Vagrant file that I downloaded at the start of the tutorial, config.vm.hostname = "ckiser-starter". Are nodes machines? or types of machines? I think the later, but not sure. I would like to be able to test out my configuration changes on a local VM before pushing them to my Linode. So is that 1 node and 2 environments? or 2 nodes? I think the former but am not 100% sure.