Skip to content

Instantly share code, notes, and snippets.

@aoktox

aoktox/Vagrantfile

Last active Sep 20, 2020
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@aoktox 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