multiple VMs based on same base image

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

multiple VMs based on same base image

Vince Skahan
Coming from a VMware Workstation background, I'm struggling a bit with the vagrant commands and what's where under the hood.

What I'm trying to do is:
  • create multiple VMs based on the same base distro (say ubuntu/trusty64)
  • name the multiple VMs individually (say 'hostA' and 'hostB')
  • be able to start/stop them independently
  • be able to run them simultaneously as needed
  • definitely be able to have them configured differently when I get done with them
To me, this isn't the same as https://docs.vagrantup.com/v2/multi-machine/index.html which is more like a VMware Workstation Team kind of scenario (correct me if I'm reading it wrong).  I just want to have multiple VMs derived from the same base starting point that I can start/stop/alter differently.

I'm running vagrant-1.6.5 on a Macbook with VirtualBox if that matters...

Any help appreciated....thanks...


--
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: multiple VMs based on same base image

Alvaro Miranda Aguilera
the answer to all the questions is yes.
 
you have 2 ways of attack this problem.
 
- The machies are indepent, so you create separate vagrantfiles
- the machines are relates, so you create a multi-machine vagrantfile
 
you are in the second, so, start with the same multi-machine vagrantfile
 
The important bits are pretty much here:
 
config.vm.define "web" do |web|
    web.vm.box = "hashicorp/precise64"
  end

what ever is local for that machine should go was web.* isnide the define block
 
config.* // stuff that impact all the machines but are considered first
 
config.vm.define "web1" do |web1|
    web.vm.box = "hashicorp/precise64"
    web.* // stuff that impact this local machine
end
 
config.vm.define "web2" do |web2|
    web2.vm.box = "hashicorp/precise64"
    web2.* // stuff that impact this local machine
end
 
config.* // stuff that impact all the machines but are considered last
 
Vagrant files are read couple of times and whatever is in there is what gets executed.. top to bottom,,. so the here web1 will be created first, then web2 will be created as last.
 
when the list of commands is built, all the instructions (box, provisioner, provider, etc) is read top to bottom, so, what you will see in a multi machine vagrant up will be like:
 
- first machine created
- what you define first (as config.) take is as a global instuction set.. gets run
- then what ever is inside each define block
- what you define last
 
- second machine created
- what you define first (as config.) take is as a global instuction set.. gets run
- then what ever is inside each define block
- what you define last
 
..
 
..
 
- last machine created
- what you define first (as config.) take is as a global instuction set.. gets run
- then what ever is inside each define block
- what you define last

Hope this helps.
Alvaro.
 

 
On Fri, Oct 24, 2014 at 8:34 AM, Vince Skahan <[hidden email]> wrote:
Coming from a VMware Workstation background, I'm struggling a bit with the vagrant commands and what's where under the hood.

What I'm trying to do is:
  • create multiple VMs based on the same base distro (say ubuntu/trusty64)
  • name the multiple VMs individually (say 'hostA' and 'hostB')
  • be able to start/stop them independently
  • be able to run them simultaneously as needed
  • definitely be able to have them configured differently when I get done with them
To me, this isn't the same as https://docs.vagrantup.com/v2/multi-machine/index.html which is more like a VMware Workstation Team kind of scenario (correct me if I'm reading it wrong).  I just want to have multiple VMs derived from the same base starting point that I can start/stop/alter differently.

I'm running vagrant-1.6.5 on a Macbook with VirtualBox if that matters...

Any help appreciated....thanks...


--
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: multiple VMs based on same base image

VMTrooper
In reply to this post by Vince Skahan
Hello Vince,

In addition to what Alvaro suggested, you can take advantage of the fact that Vagrant is written in Ruby, and you can use standard Ruby features like Lists\Hashes and loops to decrease the amount of code necessary to build multiple VMs in a single Vagrantfile.


Just ignore the lines about Puppet provisioning and the network and VM setting customizations.

Let us know if that helps,
Trevor

On Thursday, October 23, 2014 12:34:21 PM UTC-7, Vince Skahan wrote:
Coming from a VMware Workstation background, I'm struggling a bit with the vagrant commands and what's where under the hood.

What I'm trying to do is:
  • create multiple VMs based on the same base distro (say ubuntu/trusty64)
  • name the multiple VMs individually (say 'hostA' and 'hostB')
  • be able to start/stop them independently
  • be able to run them simultaneously as needed
  • definitely be able to have them configured differently when I get done with them
To me, this isn't the same as <a href="https://docs.vagrantup.com/v2/multi-machine/index.html" target="_blank" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fdocs.vagrantup.com%2Fv2%2Fmulti-machine%2Findex.html\46sa\75D\46sntz\0751\46usg\75AFQjCNGhBZTugnmxfkATZo8MgBTx7bLhMw';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fdocs.vagrantup.com%2Fv2%2Fmulti-machine%2Findex.html\46sa\75D\46sntz\0751\46usg\75AFQjCNGhBZTugnmxfkATZo8MgBTx7bLhMw';return true;">https://docs.vagrantup.com/v2/multi-machine/index.html which is more like a VMware Workstation Team kind of scenario (correct me if I'm reading it wrong).  I just want to have multiple VMs derived from the same base starting point that I can start/stop/alter differently.

I'm running vagrant-1.6.5 on a Macbook with VirtualBox if that matters...

Any help appreciated....thanks...


--
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.