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
?
Yes, you can specify multiple machines by using the
config.vm.define
method call, for example:See: Defining multiple machines at Vagranup Docs and Providers
To run VM locally you can run:
vagrant up --provider=virtualbox
and if you'd like to run VM using different provider then you can use:vagrant up --provider=aws
However, remember that you have to install appropriate provider plugin before you will use it.
add box for each provider
and your Vagrantfile should look like
then create on each provider using following commands
You can choose which provider you want to run by
--provider
parameter.Here is ruby code in
Vagrantfile
which can run different VM depending which provider you have chosen:So by the default provider is virtualbox, but you can specify from the command line, like:
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>
.From the Vagrant docs:
eg.: First install puppet in the machine and then run some puppet manifests: