Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple providers in a single vagrant file?

I've got a vagrant file that builds a local VM. I want to add the EC2 provider and have the option of either provisioning a local VM or one on EC2.

Can I create configs for multiple providers in the same Vagrantfile and somehow choose which to run when I do vagrant up?

like image 412
jbrown Avatar asked Jun 12 '13 07:06

jbrown


People also ask

Can I launch more than one VM from a single Vagrantfile?

Often times you might want to launch more than one VM of a related application with different configurations. In this case, you don’t have to create multiple vagrant configurations. You can use a single Vagrantfile with multiple configurations as shown below.

Do all vagrant providers work with any Vagrantfile?

While well-behaved Vagrant providers should work with any Vagrantfile with sane defaults, providers generally expose unique configuration options so that you can get the most out of each provider. This provider-specific configuration is done within the Vagrantfile in a way that is portable, easy to use, and easy to understand.

How can multiple machines be defined within the same Vagrantfile?

Multiple machines are defined within the same project Vagrantfile using the config.vm.define method call. This configuration directive is a little funny, because it creates a Vagrant configuration within a configuration. An example shows this best: As you can see, config.vm.define takes a block with another variable.

What is provider-specific configuration in Vagrant?

Provider-specific configuration is meant as a way to expose more options to get the most of the provider of your choice. It is not meant as a roadblock to running against a specific provider. Providers can also override non-provider specific configuration, such as config.vm.box and any other Vagrant configuration.


2 Answers

You can use a multi-vm environment, where every VM can be provisioned with a different provider and you can choose on commandline which one you want to vagrant up <machine>.

like image 111
cmur2 Avatar answered Sep 18 '22 13:09

cmur2


add box for each provider

> vagrant box add precise64 http://file.vagrantup.com/precise64.box
> vagrant box add precise64 http://file.vagrantup.com/precise64_vmware_fusion.box

and your Vagrantfile should look like

Vagrant.configure(2) do |config|
  config.vm.box="precise64"

  config.vm.provider "virtualbox" do |v|
    v.customize ["modifyvm", :id, "--memory", "2048"]
  end

  config.vm.provider "vmware_fusion" do |v|
    v.vmx["memsize"] = "2048"
  end
end

then create on each provider using following commands

> vagrant up --provider=virtualbox
> vagrant up --provider=vmware_fusion
like image 25
rravuri Avatar answered Sep 18 '22 13:09

rravuri