Blog Posts



Things Ian Says

Creating vagrant boxes with veewee and packer

This is an old article, and the technologies used in here may have changed significantly since I wrote it. Proceed with caution.

I’ve been creating a few vagrant base boxes recently — some for a DevOps course I am putting together, and some for investigations in my current project — and I thought I’d quickly share my experiences of the two tools: veewee and packer.

My First Basebox

The first tool I found to build vagrant base boxes was veewee. I installed it as a ruby gem (which made it an easy install), but the problem I quickly came up against was that this gem did not track the latest developments as quickly as would be useful. Veewee has templates for popular OS’s (e.g. CentOS and Ubuntu) which you use to create your base box (in conjunction with the appropriate ISO’s and extensions). The first problem I encountered was that the gem version did not have a template for CentOS 6.5 (only for 6.4). At the time, I thought this wasn’t too big a deal, so pushed on with this.

The basic approach is:

  • Use veewee to create the initial OS install
  • Ssh into the created box and customise it how you wish — e.g. by installing the packages you want
  • Use veewee to save a vagrant base box from this
  • I had a few problems getting this to work smoothly, which I think was down to the gem not being completely up to date. Most notably, I could not get the VirtualBox extras to install correctly, until a lot of googling indicated this was due to needing more recent kernel libraries and was sorted with a yum install kernel.

This gave me my first working basebox (at the start of January) which I used for most of my vagrant needs for around a month.

From Veewee to Packer

I had used my basebox to troubleshoot a few issues on my current project (mainly around loadbalancing), but I wanted to put together a new one more suited to the stack being used on the project. So, I dusted off veewee and started looking at my wishlist.

First thing was that I wanted CentOS 6.5, so I needed to update veewee. I tried updating the gem, but no newer version was available. So I cloned it straight from github and then used ruby Bundler to get a runnable version. I’m not sure whether it was because I was using rvm or for some other reason, but I could then only run veewee from within the directory I had cloned it to.

At this point I thought I would take a look at another tool which a colleague had mentioned to me — packer. My intention was to see whether I preferred it and then to decide whether to spend more time trying to set up veewee or not.

Packer’s approach is slightly different from veewee’s in that running a “packer build” command creates the base box in one go. Any customisation you want, you have to include it in scripts to be run during the build process.

As well as packer itself, you need a json file which describes the build process and some scripts to set everything up. I found a set of scripts on github and used them as my example. I then tweaked the json to customise it slightly and created a shell script to install all the packages I wanted in my base box.

The build process was then as simple as running the packer command and waiting.

The Comparison

The following is just based on my above experiences and I would be grateful for any comments with other experiences for contrast.

Overall, I feel that packer is the slicker tool and it has worked well for me. The hassle of cloning veewee and then using Bundler to get something runnable makes veewee less attractive in comparison. Perhaps if I was some sort of ruby guru I would find veewee easier to use.

What I did like about veewee was that you got a middle step between create and save, where you could go into the VM you’d created and customise it to be how you like. Once you’ve got it exactly the way you like, you can save it. With packer, you need to script it all beforehand.

I appreciate that for industrialisation the packer approach is better, but if you’re trying to put together a quick base box to use for a few days, the manual tweaking that veewee offers is tempting.

I should also mention a third approach, which is to stick with a vanilla base box and put all the customisation in the Vagrantfile at provisioning time. That is obviously a pattern which vagrant was designed for, but my use case is that sometimes I don’t have network access and therefore I want all my tools in the basebox to begin with.

The Conclusion

No real conclusion (I’ve just been using packer for a day), but at the moment I am tending towards packer as my vagrant box creator of choice.