Multiple machines in an embedded Vagrantfile?

69 views
Skip to first unread message

Richard Wellum

unread,
Feb 23, 2016, 9:15:12 AM2/23/16
to Vagrant
Is it possible to bring up multiple machines, with an embedded (./include/Vagrantfile)?

And if this is supported - what are the vagrant [init/add/up] steps? For example usually when you do vagrant up - you have to --name the VM - but there are multiple VM's defined in the Vagrantfile. Similar for vagrant init - it either does a default or expects a machine(vm) name.

Alvaro Miranda Aguilera

unread,
Feb 23, 2016, 9:26:58 PM2/23/16
to vagra...@googlegroups.com
Hello,

Lets move into steps first.

You can have a box that include a vagrantfile, and that vagrantfile can be a multi machine

so you can work first on getting the multi machine setup working.

vagrant by default will work with 1 vm, that is called default.

So in a multi node setup you can define new boxes, and vagrant up will start all of them

more info here:


The order is top to botom

so if you want 3 web servers you can do

web3
web2
web1

if you need to happen something after 1 is done.


This is how I start 3 VM.

one called server and 2 called agent, so you can get some ideas:

  #server box

  config.vm.define "server" do |server|

    server.vm.box = "alvaro/oracle6-dev-491"

    server.vm.hostname = "server"

    ip="192.168.10.10"

    server.vm.network "private_network", ip: ip

  end


  #agent box

  (1..2).each do |i|

    vm_name = "agent#{i}"

    config.vm.define vm_name do |agent|

      agent.vm.box = "alvaro/oracle6-agent"

      agent.vm.hostname = vm_name

      ip="192.168.10.#{10+i}"

      agent.vm.network "private_network", ip: ip

    end

  end


Once the Vagrantfile is in place, vagrant status will check for all the boxes. ie:


mini:dev_consul kikitux$ vagrant status

Current machine states:


server                    not created (vmware_fusion)

agent1                    not created (vmware_fusion)

agent2                    not created (vmware_fusion)


This environment represents multiple VMs. The VMs are all listed

above with their current state. For more information about a specific

VM, run `vagrant status NAME`.

mini:dev_consul kikitux$ 




On Wed, Feb 24, 2016 at 3:15 AM, Richard Wellum <richw...@gmail.com> wrote:
Is it possible to bring up multiple machines, with an embedded (./include/Vagrantfile)?

And if this is supported - what are the vagrant [init/add/up] steps? For example usually when you do vagrant up - you have to --name the VM - but there are multiple VM's defined in the Vagrantfile. Similar for vagrant init - it either does a default or expects a machine(vm) name.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
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 vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/b91c53ea-b097-4fe2-8239-9e9afc3c12ad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages