In a vagrantfile I would like to set some provider specific variables. After realising that I cannot set the values in these sections (because of this):
config.vm.provider "virtualbox" do |vb, override|
...
end
... this is my workaround - Basically I set an environment variable that I can check and then set the provider settings accordingly:
if ENV['VAGRANT_PROVIDER'] == 'virtualbox'
config.hostmanager.enabled = true
tld = "local"
dbadmin_pass = "vagrant"
elsif ENV['VAGRANT_PROVIDER'] == 'aws'
config.hostmanager.enabled = false
tld = "com"
dbadmin_pass = "myprodpass"
else
raise Vagrant::Errors::VagrantError.new, "Missing environment variable or invalid value: VAGRANT_PROVIDER [virtualbox|aws]"
end
This is really hacky though and requires me to set the environment variable as well.
I'm not a ruby expert at all - Is there a better way to set provider specific variables?
You can define providers like:
Then start your vagrant with:
or
Make sure you override any provider specific variables, see the Vagrant Docs - Overriding Configuration section.