Added dynamic creation of webservers and lb's

This commit is contained in:
strNophix 2022-02-23 15:47:58 +01:00
parent 2e6c7542ba
commit fefc1f228c

@ -1,18 +1,73 @@
$ip_int = #{ipAddr}
def increment_ip()
ip = "192.168.56.%d" % [$ip_int]
$ip_int += 1
return ip
end
Vagrant.configure("2") do |config|
config.ssh.insert_key = false
config.ssh.private_key_path = ["./.ssh/id_rsa","~/.vagrant.d/insecure_private_key"]
config.vm.define "#{customerName}-bloated-debian-web01" do |web01|
web01.vm.box = "ubuntu/focal64"
web01.vm.hostname = "#{customerName}-bloated-debian-web01"
num_webserver = #{numWebserver}
num_loadbalancer = #{numLoadbalancers}
web01.vm.network :private_network, ip: "#{ipAddr}" # "192.168.56.12"
webserver_ids = []
(1..num_webserver).each do |nth|
machine_id = "#{customerName}-bloated-debian-web%d" % [nth]
webserver_ids = webserver_ids.push(machine_id)
web01.vm.provision "file", source: "./.ssh/id_rsa.pub", destination: "~/.ssh/authorized_keys"
web01.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
vb.gui = false
vb.name = "#{customerName}-bloated-debian-web01"
config.vm.define machine_id do |web|
web.vm.box = "ubuntu/focal64"
web.vm.hostname = machine_id
web.vm.network "private_network", ip: increment_ip()
web.vm.provision "file", source: "./.ssh/id_rsa.pub", destination: "~/.ssh/authorized_keys"
web.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
vb.gui = false
vb.name = machine_id
end
if nth == num_webserver
config.vm.provision "ansible" do |ansible|
ansible.playbook = "./playbooks/install_nginx.yml"
ansible.groups = {
"webserver" => webserver_ids
}
end
end
end
end
lbserver_ids = []
(1..num_loadbalancer).each do |nth|
machine_id = "#{customerName}-bloated-debian-lb%d" % [nth]
lbserver_ids = lbserver_ids.push(machine_id)
config.vm.define machine_id do |web|
web.vm.box = "ubuntu/focal64"
web.vm.hostname = machine_id
web.vm.network "private_network", ip: increment_ip()
web.vm.provision "file", source: "./.ssh/id_rsa.pub", destination: "~/.ssh/authorized_keys"
web.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
vb.gui = false
vb.name = machine_id
end
if nth == num_loadbalancer
config.vm.provision "ansible" do |ansible|
ansible.playbook = "./playbooks/install_loadbalancer.yml"
ansible.groups = {
"loadbalancer" => lbserver_ids
}
end
end
end
end
end