Skip to content

Instantly share code, notes, and snippets.

@mike-hearn
Created July 2, 2016 16:02
Show Gist options
  • Save mike-hearn/7b5fe336f472f3d24b14cff1b69437dd to your computer and use it in GitHub Desktop.
Save mike-hearn/7b5fe336f472f3d24b14cff1b69437dd to your computer and use it in GitHub Desktop.
Multi-machine Vagrant config with private networking
# -*- mode: ruby -*-
# vi: set ft=ruby :
boxes = [
{
:name => "server1",
:eth1 => "192.168.205.10",
:mem => "1024",
:cpu => "1"
},
{
:name => "server2",
:eth1 => "192.168.205.11",
:mem => "1024",
:cpu => "2"
},
{
:name => "server3",
:eth1 => "192.168.205.12",
:mem => "2048",
:cpu => "2"
}
]
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/xenial64"
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
boxes.each do |opts|
config.vm.define opts[:name] do |config|
config.vm.hostname = opts[:name]
config.vm.provider "vmware_fusion" do |v|
v.vmx["memsize"] = opts[:mem]
v.vmx["numvcpus"] = opts[:cpu]
end
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--name", opts[:name]]
v.customize ["modifyvm", :id, "--memory", opts[:mem]]
v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
end
config.vm.network :private_network, ip: opts[:eth1]
end
end
end
@zimmertr
Copy link

Thanks for showing the boxes array trick!

@emiglobetrotting
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment