ThorneLabs

Multi-machine Vagrantfile for VirtualBox or VMware Fusion

• Updated May 13, 2017


The following Vagrantfile shows the syntax for setting up multiple virtual machines using VirtualBox or VMware Fusion.

In addition, the example shows the syntax for globally turning off:

  • shared folders
  • setting each virtual machine’s hostname
  • setting each virtual machine’s CPU
  • setting each virtual machine’s memory
  • adding a private NIC on the 192.168.205.0/24 network.

I have also put together a multi-machine Vagrantfile with shorter, cleaner syntax using JSON and loops.

Example Vagrantfile

# -*- mode: ruby -*-

# vi: set ft=ruby :
 
VAGRANTFILE_API_VERSION = "2"
 
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
 
  config.vm.box = "base"

  config.vm.provider "vmware_fusion" do |v, override|
    override.vm.box = "base"
  end
 
  # Turn off shared folders
  config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
 
  # Begin server1
  config.vm.define "server1" do |server1|
    server1.vm.hostname = "server1"

    server1.vm.provider "vmware_fusion" do |v|
        v.vmx["numvcpus"] = "1"
        v.vmx["memsize"] = "1024"
    end
 
    server1.vm.provider "virtualbox" do |v|
        v.customize [ "modifyvm", :id, "--cpus", "1" ]
        v.customize [ "modifyvm", :id, "--memory", "1024" ]
    end

    server1.vm.network "private_network", ip: "192.168.205.10"
  end
  # End server1
 
  # Begin server2
  config.vm.define "server2" do |server2|
    server2.vm.hostname = "server2"
 
    server2.vm.provider "vmware_fusion" do |v|
        v.vmx["numvcpus"] = "2"
        v.vmx["memsize"] = "1024"
    end
 
    server2.vm.provider "virtualbox" do |v|
        v.customize [ "modifyvm", :id, "--cpus", "2" ]
        v.customize [ "modifyvm", :id, "--memory", "1024" ]
    end

    server2.vm.network "private_network", ip: "192.168.205.11"
  end
  # End server2
 
  # Begin server3
  config.vm.define "server3" do |server3|
    server3.vm.hostname = "server3"
 
    server3.vm.provider "vmware_fusion" do |v|
        v.vmx["numvcpus"] = "2"
        v.vmx["memsize"] = "2048"
    end
 
    server3.vm.provider "virtualbox" do |v|
        v.customize [ "modifyvm", :id, "--cpus", "2" ]
        v.customize [ "modifyvm", :id, "--memory", "2048" ]
    end

    server3.vm.network "private_network", ip: "192.168.205.12"
  end
  # End server3
end

If you found this post useful and would like to help support this site - and get something for yourself - sign up for any of the services listed below through the provided affiliate links. I will receive a referral payment from any of the services you sign-up for.

Get faster shipping and more with Amazon Prime: About to order something from Amazon but want to get more value out of the money you would normally pay for shipping? Sign-up for a free 30-day trial of Amazon Prime to get free two-day shipping, access to thousands of movies and TV shows, and more.

Thanks for reading and take care.