Last active
September 20, 2020 03:48
-
-
Save aoktox/d5033bb383f93fa2d752574cd9da37f8 to your computer and use it in GitHub Desktop.
Vagrant multiple machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
❯ 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`.