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 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 :
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| = "base"

  config.vm.provider "vmware_fusion" do |v, override| = "base"
  # 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"
    server1.vm.provider "virtualbox" do |v|
        v.customize [ "modifyvm", :id, "--cpus", "1" ]
        v.customize [ "modifyvm", :id, "--memory", "1024" ]
    end "private_network", ip: ""
  # 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"
    server2.vm.provider "virtualbox" do |v|
        v.customize [ "modifyvm", :id, "--cpus", "2" ]
        v.customize [ "modifyvm", :id, "--memory", "1024" ]
    end "private_network", ip: ""
  # 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"
    server3.vm.provider "virtualbox" do |v|
        v.customize [ "modifyvm", :id, "--cpus", "2" ]
        v.customize [ "modifyvm", :id, "--memory", "2048" ]
    end "private_network", ip: ""
  # End server3

If you found this post useful, you can help support this site and get something for yourself by signing up for any of the services listed below through the provided links.

The following links are part of affiliate programs, and I will receive a referral payment from any of the services you sign-up for.

  • Get Faster Shipping: Perhaps you're about to order some stuff on 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.
  • Start Investing Now: Are you looking to start investing some of your disposable saved income? Get started by opening an account with Webull, where upon sign-up and opening a brokerage account with an initial deposit of at least $100 you will receive 1 stock valued (subject to change based on normal market movement) between $8 and $1600.

Thanks for reading and take care.