Vagrant 1.3.x and Virtualbox 4.3 backwards compatibility

Jeroen van Dijk
Jeroen van Dijk

20 oktober 2013

Virtualbox & Vagrant is `the` combination I love to fire up any virtual machine you’d like to work with. It makes life so easy, that I cannot remember working without it.
But… Although Vagrant is a stable tool for usage, the development cycle is not guaranteed to be forward compatible. You have already seen this when version 1.1.0 was released which introduced a new Vagrantfile structure. And it still happens!
The documentation of Vagrant states that up till version 2.0 it’s not guaranteed that configuration will stay the same. This might create a problem when your company’s development process relies on it.

When version 1.3.0 was introduced one simple change broke access to all our development environments. The :extra parameter for a synced_folder action, was changed into :mount_options. Then you think… just update!? But it isn’t that easy. Updating 30 different projects with every Vagrant change is just not an option. On top of that… in our case more then 20 developers have to update at the same moment as well.

The only option you currently have is creating your own backwards compatibility. Luckility this can be done! Within the Vagrantfile you can use Ruby to create this backwards compatibility.

Let’s start…

First up: We need the version of Vagrant the user is running. Because there is no documentation about this specific item, I started with `vagrant -v`. In the Vagrantfile you can add the following code to read data from the CLI.

@version = %x(vagrant -v)

While I was busy trying to parse the output I found another inconsistency. Version 1.2.x returns `Vagrant version 1.2.x` where version 1.3.x returns `Vagrant 1.3.x`. Of course you can overcome this with some awk, but that’s not a reliable solution for Windows users.


It’s not really documented on the website, but a github repository search gave the answer. You can access the version number via Vagrant::VERSION. Luckily, that constant hasn’t changed since the start of the project.
And then things become easy as you can see in the following code snippet. Just add these lines to your Vagrantfile to have backwards compatibility between version 1.2.x and 1.3.x.

if Vagrant::VERSION  'uid=500,gid=48,dmode=0775,fmode=0764')
    config.vm.synced_folder(".", "/vagrant", :mount_options => ["uid=500","gid=48","dmode=0775","fmode=0764"])

If you are paying attention, you might notice one more caveat. Not only the name of the mount option parameter has changed, so did the format. In version 1.2.x you are required to define a string, but in 1.3.x it needs to be an array. Although the logic isn’t that nice, it makes the upgrading far more easy!

This blogpost is a copy of the original version which can be found at