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
| Vagrant.configure(2) do |config|
etcHosts = ""
config.vm.box = "ubuntu/bionic64"
config.vm.box_url = "ubuntu/bionic64"
# set servers list and their parameters
NODES = [
{ :hostname => "haproxy", :ip => "xx.yy.zz.131", :mac => "", :cpus => 1, :mem => 1024, :type => "haproxy" },
{ :hostname => "s1", :ip => "xx.yy.zz.133", :mac => "005056045080", :cpus => 2, :mem => 10240, :type => "kub" },
{ :hostname => "s2", :ip => "xx.yy.zz.134", :mac => "", :cpus => 2, :mem => 8192, :type => "kub" },
{ :hostname => "s3", :ip => "xx.yy.zz.135", :mac => "", :cpus => 2, :mem => 8192, :type => "kub" }
]
# define /etc/hosts for all servers
NODES.each do |node|
if node[:type] != "haproxy"
etcHosts += "echo '" + node[:ip] + " " + node[:hostname] + "' >> /etc/hosts" + "\n"
else
etcHosts += "echo '" + node[:ip] + " " + node[:hostname] + " monclust.kub ' >> /etc/hosts" + "\n"
end
end #end NODES
# run installation
NODES.each do |node|
config.vm.define node[:hostname] do |cfg|
cfg.vm.hostname = node[:hostname]
if node[:mac] != ""
cfg.vm.network "public_network", ip: node[:ip], mac: node[:mac]
# default router
config.vm.provision "shell",
run: "always",
inline: "route add default gw aa.bb.cc.254"
# delete default gw on eth0
config.vm.provision "shell",
run: "always",
inline: "eval `route -n | awk '{ if ($8 ==\"eth0\" && $2 != \"0.0.0.0\") print \"route del default gw \" $2; }'`"
else
cfg.vm.network "public_network", ip: node[:ip]
end
cfg.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--cpus", node[:cpus] ]
v.customize ["modifyvm", :id, "--memory", node[:mem] ]
v.customize ["modifyvm", :id, "--name", node[:hostname] ]
end #end provider
#for all
cfg.vm.provision :shell, :inline => etcHosts
end # end config
end # end nodes |
Partager