HOWTO get started with chef, librarian-chef and vagrant

30 Aug 2013, 14:51

I’ve used Chef to automate environments before, and the more I work at different, large clients, the more I see the need to use it, or puppet, for controlling/managing servers. Now, I don’t want to start a flamewar here, but what’s the deal with… no, just kidding, I technically have tshirts from both Chef and Puppet, so I’m as impartial as you can get! Since a new gig I have starting up soon promises to make me into the top chef in the office, I thought it was time to dust off my skills with a new HOWTO to get Chef installed, using Vagrant, started and configured. Bonus, I found that it’s actually easier than it used to be to get up to snuff, now it can be condensed into a few steps.

Install needed software

Configure Vagrant with a base box definition

Configure Chef by adding cookbook with Librarian-chef

Tell Vagrant about the new cookbook

Build a vagrant instance, then have Chef-solo install a webserver on it

Simple huh? So let’s get started.

Install needed software

Debian

For this example I’m running Debian GNU/Linux on the Jessie (testing) branch. Regardless, we need to have contrib in our /etc/apt/sources.list to get Virtualbox

deb http://http.debian.net/debian/ jessie main contrib

If you already have a line with main in it, just add contrib to the end

That’s it, now by default this setups up Virtualbox to run on boot, which I don’t want, so I changed LOAD_VBOXDRV_MODULE in /etc/default/virtualbox to 0

sed -s -i 's/\=1/\=0/' /etc/default/virtualbox

Mac OS X

For this example I’m running on my (t)rusty Apple MacBook Pro (5,5 2009) with 4 Gig RAM. All we need to do is visit the VirtualBox download page and grab the package for OS X hosts x86/amd64. While we’re there we’ll also download the VirtualBox 4.2.16 Oracle VM VirtualBox Extension Pack. Once downloaded click on the VirtualBox dmg, install it as normal, then open the VirtualBox Extension Pack, it will automatically open in VirutalBox and install, no big drama there, and we’re done.

The rest of the doc is the same independant of what you’re running this on.

Now we’ll install vagrant, now while while your repo may have a version of vagrant to install, don’t install it! Those are always older than what rubygems provides, plus somewhere down the line it will cause breakage; trust me, I’ve done it before. So, first install rubygems

Ok, it’s installed other cookbooks that it thinks we might need, we won’t need apt because we’re rocking CentOS, but hey, that’s cool. Also notice there is not an apache2 cookbook in the directory anymore, so it’s cleaned up what we didn’t need, nice!

Now let’s tell Vagrantfile about the change

cd -
vi Vagrantfile

And just change where it says apache2 to nginx

chef.add_recipe "nginx"

and now kick off a build of that box

vagrant up

Do your verification as above, but notice we’re not rocking nginx, as it should be. Whew, that was quick, but hey, it’s something to build on, and I’ll try to demonstrate that going forward by using this same setup to deploy to ‘real’ virtual machines in the future. Questions/comments, sound off on Twitter, or hit me up via the contact page.