Vagrant: multiple virtual machines in one Vagrantfile

Few days ago, I needed to test an Ansible playbook to configure several node machines. To do that, I wanted to setup 3 virtual machines (plus one with Ansible to run the tests).

So, I wrote a Vagrantfile to define 4 virtual machines. Each VM is defined in the Vagrant.configure block this way:

config.vm.define "vm_name" do |machine| = "precise64"
  machine.vm.hostname = "machine_name"
  machine.vm.box_url = "ubuntu/precise64" :private_network, ip: "" :forwarded_port, guest: 80, host: 8080, id: "http" :forwarded_port, guest: 22, host: 10022, id: "ssh"

  machine.vm.provider "virtualbox" do |vb|
    vb.memory = "512"

For each, I set a different vm_name, hostname and I incremented ip and ports.


That’s it!

0 commentaire

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *