Check vagrant version in Vagrantfile

To access the used version of vagrant in a vagrant file you can use the (undocumented) Vagrant::VERSIONconstant. Combine this with Ruby's own Gem::Version and you can create a nice switch to handle deprecated configuration in the Vagrantfile.

Here is an example:

if >='1.2')
  share_folder_options = {:create => true, :nfs => false, :mount_options => ['dmode=777','fmode=777']}
  share_folder_options = {:create => true, :nfs => false, :extra => 'dmode=777,fmode=777'}

One Comment

Respond to this post

Steffen Gebert wrote

Nice post, Christian!

In the upcoming version 1.4 of Vagrant, there will be even a function for that:

> The Vagrant.require_version function can be used at the top of a Vagrantfile to enforce a minimum/maximum Vagrant version.

But yes, you would lock out all users below 1.4, if you would use it once it's released ;-)


2013-12-02 12:11