Skip to content

Instantly share code, notes, and snippets.

@aoktox
Last active September 20, 2020 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aoktox/d5033bb383f93fa2d752574cd9da37f8 to your computer and use it in GitHub Desktop.
Save aoktox/d5033bb383f93fa2d752574cd9da37f8 to your computer and use it in GitHub Desktop.
Vagrant multiple machine
$script = <<SCRIPT
echo "Installing python..."
apt-get update
apt-get install -y python-minimal
SCRIPT
SPECIALS = {
"master" => { :ip => "192.168.99.100", :ram => 1024 },
"hiddensecondary" => { :ip => "192.168.99.101", :ram => 512 }
}
NODES_COUNT = 2
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
# Common provission, applied to all machines
config.vm.provision "shell", inline: $script
SPECIALS.each_with_index do |(hostname, attributes), index|
config.vm.define hostname do |nodeconfig|
nodeconfig.vm.hostname = hostname
nodeconfig.vm.network :private_network, ip: attributes[:ip]
nodeconfig.vm.provider "virtualbox" do |vb|
vb.memory = attributes[:ram]
end
end
end
(1..NODES_COUNT).each do |i|
config.vm.define "node-#{i}" do |node|
node.vm.network "private_network", ip: "192.168.99.1#{i}"
node.vm.hostname = "node#{i}"
node.vm.provider "virtualbox" do |vb|
vb.memory = "512"
end
end
end
end
@aoktox
Copy link
Author

aoktox commented Sep 20, 2020

❯ vagrant status
Current machine states:

master                    running (virtualbox)
hiddensecondary           running (virtualbox)
node-1                    running (virtualbox)
node-2                    running (virtualbox)

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`.

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