Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify default provider in Vagrantfile

Tags:

vagrant

I'd like to specify directly in the vagrantfile which provider to use by default for each VM.

For example, given this vagrantfile:

# Vagrantfile
[...]
config.vm.define 'dev_vm' do |machine|
  machine.vm.provider :libvirt do |os|
   [...]
  end
  # machine.default_provider = :libvirt
end

config.vm.define 'production_vm' do |machine|
  machine.vm.provider :openstack do |os|
   [...]
  end
  # machine.default_provider = :openstack
end

To boot up the following to VMs, I have to issue two commands currently:

vagrant up --provider=libvirt  dev_vm
vagrant up --provider=openstack production_vm

I'd like to bring up both with a single vagrant up, especially because I'm running quite a few more machines. Some configuration like the commented machine.default_provider = :openstack would be fantastic to have.

Is there a way to do so?

like image 346
Luca Invernizzi Avatar asked Sep 05 '25 19:09

Luca Invernizzi


1 Answers

I don't think there is any easy way to do it. Vagrant will currently use the same provider during the whole run so it could possibly be quite big code change to support this.

Maybe wrapper scripts are the easiest solution now.

Another workaround would be to use separate Vagrantfiles for the VMs and set VAGRANT_DEFAULT_PROVIDER in each. If there is a lot of common config, you could extract it to e.g. Vagrantfile.common, which is included by the others. Something like:

# Vagrantfile 1

ENV['VAGRANT_DEFAULT_PROVIDER'] = 'libvirt'

# assume the common config is in parent directory
load File.expand_path('../../Vagrantfile.common', __FILE__)

Vagrant.configure('2') do |config|
  # ...
end
like image 82
tmatilai Avatar answered Sep 12 '25 04:09

tmatilai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!