» Configuration
While well-behaved Vagrant providers should work with any Vagrantfile with sanedefaults, providers generally expose unique configurationoptions so that you can get the most out of each provider.
This provider-specific configuration is done within the Vagrantfilein a way that is portable, easy to use, and easy to understand.
» Portability
An important fact is that even if you configure other providers withina Vagrantfile, the Vagrantfile remains portable even to individuals whodo not necessarily have that provider installed.
For example, if you configure VMware Fusion and send it to an individualwho does not have the VMware Fusion provider, Vagrant will silently ignorethat part of the configuration.
» Provider Configuration
Configuring a specific provider looks like this:
Vagrant.configure("2") do |config|
# ...
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
end
end
Multiple config.vm.provider
blocks can exist to configure multipleproviders.
The configuration format should look very similar to how provisionersare configured. The config.vm.provider
takes a single parameter: thename of the provider being configured. Then, an inner block with customconfiguration options is exposed that can be used to configure thatprovider.
This inner configuration differs among providers, so please read thedocumentation for your provider of choice to see available configurationoptions.
Remember, some providers do not require any provider-specific configurationand work directly out of the box. Provider-specific configuration is meantas a way to expose more options to get the most of the provider of yourchoice. It is not meant as a roadblock to running against a specific provider.
» Overriding Configuration
Providers can also override non-provider specific configuration, suchas config.vm.box
and any other Vagrant configuration. This is done byspecifying a second argument to config.vm.provider
. This argument isjust like the normal config
, so set any settings you want, and they willbe overridden only for that provider.
Example:
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.provider "vmware_fusion" do |v, override|
override.vm.box = "precise64_fusion"
end
end
In the above case, Vagrant will use the "precise64" box by default, butwill use "precise64_fusion" if the VMware Fusion provider is used.
The Vagrant Way: The proper "Vagrant way" is toavoid any provider-specific overrides if possible by making boxesfor multiple providers that are as identical as possible, since boxnames can map to multiple providers. However, this is not always possible,and in those cases, overrides are available.