I have a Vagrantfile describing an environment which only works with VirtualBox >= 4.3. How can I add a check to the Vagrantfile to enforce this? Thanks.
Vagrant doesn't have this enforcement. It would be possible to do so via maybe a config.vm.provider provider-specific configuration, but that also doesn't exist for VirtualBox at the moment. I've gotten this requested once in a couple years (twice now), so the priority is low enough that we have no plans to push this higher.
But, this isn't a bad request. Hopefully someone contributes it!
(Closing since we don't keep open requests we don't intend on filling officially)
I'll keep it open for some time to see if someone does it. After a certain point of inactivity, I'll close, just to give it a chance on the issue list.
Thanks. Actually I already had a look at this. It seems the version is already available via VagrantPlugins::ProviderVirtualBox::Driver::Meta#version, but based on a quick pry, there's no way of accessing the provider object from the config object. So I think this might require modifying plugins/kernel_v2/config/vm.rb so that the provider is accessible from the config... or something like that. I haven't got my head around all the code yet, e.g. the currying for overrides. But it feels like it should be doable.
config.vm doesn't really have any knowledge of the provider. What I would do instead is add a new setting to the VirtualBox provider-specific configuration so you can do somethign like this:
config.vm.provider "virtualbox" do |v|
v.required_version = ">= 1.2.3"
end
As I said a year ago, this was never implemented, so closing.
@aspiers did you manage to find a way ? I am exactly in the same situation, I need to enforce a minimum VirtualBox version.
I'm afraid not.
Since this feature does not exist, I've used a simple and crude workaround of just using ruby shell in the beginning of Vagrantfile. Maybe it's of help to someone:
# -*- mode: ruby -*-
# vi: set ft=ruby :
vbox_version=`vboxmanage --version`
vb = vbox_version.split('.').map{|s|s.to_i}
vb_min = [5,1,0]
if ((vb <=> vb_min) < 0)
abort('virtualbox needs to be at least of version 5.1.0 for this box')
end
VAGRANTFILE_API_VERSION = "2"
# etc...
Here is the code I use to get VirtualBox version:
def virtualbox_version()
vboxmanage = Vagrant::Util::Which.which("VBoxManage") || Vagrant::Util::Which.which("VBoxManage.exe")
if vboxmanage != nil
s = Vagrant::Util::Subprocess.execute(vboxmanage, '--version')
return s.stdout.strip!
else
return nil
end
end
Hope this helps.
@ericcitaire thanks! Your snippet is cross-platform, which is what I needed!
Here is yet another variant, the one I currently use to enforce a minimum VIrtualBox version. This too is cross-platform:
MIN_VIRTUALBOX_VERSION = Gem::Version.new('5.2.8')
version = `VBoxManage --version`
clean_version = /[0-9]+\.[0-9]+\.[0-9]+/.match(version)
if Gem::Version.new(clean_version) < MIN_VIRTUALBOX_VERSION
abort "Please upgrade to Virtualbox >= #{MIN_VIRTUALBOX_VERSION}"
end
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
Here is yet another variant, the one I currently use to enforce a minimum VIrtualBox version. This too is cross-platform: