-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVagrantfile
82 lines (71 loc) · 2.95 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
################################################################################
# Big Data Seminar. Vagrant virtual machine setup.
################################################################################
# Run 'vagrant' in this directory to interact with the virtual machines. Some
# example command lines:
# - To get help on all commands or a specific command:
# vagrant help
# vagrant help up
# - To create and start the VMs:
# vagrant up --provision --parallel
# - To connect to the first VM:
# vagrant ssh node0
# - To shut down the VMs (can be restarted with 'vagrant up'):
# vagrant halt
# - To tear down *all* VMs (also deletes all files outside the 'share' folder!):
# vagrant destroy --parallel --force
# - To tear down individual VMs (also deletes all files outside the 'share'
# folder!):
# vagrant destroy --parallel --force node0 node1
################################################################################
# The number of nodes in the virtual cluster. If this number is reduced after
# creating the VMs, the surplus ones are not destroyed automatically -- you need
# to manually run the destroy command for the corresponding nodes before
# reducing the number.
$num_nodes = 3
# If set to true, run additional setup scripts in the 'scripts' folder during VM
# provisioning
$run_scripts = false
################################################################################
$network_setup_script = <<SCRIPT
echo "Setting up networking for $(hostname)"
/bin/cat > /etc/hosts <<EOF
#{$num_nodes.times.collect {|i| "10.42.23.#{100+i} node#{i} node#{i}.cluster"}.join("\n")}
EOF
# ssh-config
sudo -u vagrant echo "StrictHostKeyChecking no" > /home/vagrant/.ssh/config
SCRIPT
require 'find'
$additional_setup_scripts = Find.find("scripts").select { |f| (File.file? f) and (f.end_with? ".sh") }.sort
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-18.04"
$num_nodes.times do |i|
config.vm.define :"node#{i}" do |node|
name = "node#{i}"
node.vm.provider "virtualbox" do |v|
v.linked_clone = true
v.name = name
v.customize ["modifyvm", :id, "--groups", "/bigdata-seminar"]
if name == "node0" then
# node0 gets additional resources for manager processes
v.memory = 2048
v.cpus = 3
else
v.memory = 1024
v.cpus = 1
end
end
node.vm.network :private_network, ip: "10.42.23.#{100 + i}", :mac => "0E#{sprintf("%010X", i + 1)}"
node.vm.network "forwarded_port", guest: 22, id: "ssh", host: 2200 + i, auto_correct: false
node.vm.hostname = "#{name}.cluster"
node.vm.provision :shell, :inline => $network_setup_script
node.vm.synced_folder '.', '/vagrant', disabled: true
node.vm.synced_folder "share", "/home/vagrant/share", create: true
if $run_scripts then
$additional_setup_scripts.each do |s|
node.vm.provision :shell, :path => s
end
end
end
end
end