Workflow for Chef with Vagrant

13 March 2011 (Sunday)

UPDATE (20/11/2011): The hacks here are superseded by updates in chef-solo and vagrant. Check out Ches Martin’s useful comment below.

I have now got a relatively decent workflow for configuring both a vagrant instance and a server using chef.

I’m using a vagrant instance configured (initially) to use chef-solo. Because I will eventually be using chef with the opscode platform, I’ve acquired a couple of hacks that help me use data-bags when using vagrant.

I could of course use the vagrant instance with chef-server linking to the platform, however I find I make too many mistakes in my config in the early work-up of my config and the additional time to (knife cookbook) upload my recipes to the server and then pull them down as well makes the development loop somewhat frustrating. Chef solo provisioning allows the vagrant instance to just link across my recipes directly into the VM and run them from there.

When I’m happy with config working in vagrant (and I destroy the vagrant and re-provision) then I try the same on my rackspace (or ec2 or whatever) instance. Usually I find I need to modify one or two things (forgotten “depends” in cookbook metadata files).

I’m doing mostly quite trivial configs which require only a one server (times two if there’s a staging and a production server), so I don’t typically have the reworking which moving from a single vagrant instance to a multi-tier server architecture would require.

Here are the hacks I use:

  1. I don’t like writing json unless I can avoid it, so like to write my roles in ruby. Chef-server translates them automatically (mantra from opscode training: “no ruby is run on the server”). I’ve created a rake task to convert roles from ruby to json: https://gist.github.com/834890
  2. A monkeypatch for Vagrant’s chef-solo provisioner to allow it to link in your data_bags folder onto the server https://gist.github.com/867958
  3. A monkeypatch for Chef-solo to allow it to manipulate data_bags very basically: https://gist.github.com/867960

One Response to “Workflow for Chef with Vagrant”

  1. Ches Martin Says:

    FYI for posterity, none of the three hacks here is necessary any longer. Chef Solo handles roles as ruby, it handles data bags, and Vagrant has a data_bags_path configuration directive for them.

    Additionally, there is a chef-solo-search project that can fill in for Chef Server for many queries:

    https://github.com/edelight/chef-solo-search


Comments are closed.