Vagrantfile collects addictional groups & hostvars

This commit is contained in:
strNophix 2022-02-23 18:28:04 +01:00
parent a60c7cbd1e
commit 4cb905883c

View File

@ -13,16 +13,26 @@ Vagrant.configure("2") do |config|
num_webserver = #{numWebserver} num_webserver = #{numWebserver}
num_loadbalancer = #{numLoadbalancers} num_loadbalancer = #{numLoadbalancers}
webserver_ids = [] ansible_groups = {
"loadbalancer" => [],
"webserver" => []
}
ansible_vars = {}
(1..num_webserver).each do |nth| (1..num_webserver).each do |nth|
machine_id = "#{customerName}-bloated-debian-web%d" % [nth] machine_id = "#{customerName}-bloated-debian-web%d" % [nth]
webserver_ids = webserver_ids.push(machine_id) ansible_groups["webserver"] << machine_id
machine_ip = increment_ip()
ansible_vars[machine_id] = {
"ipv4_address" => machine_ip
}
config.vm.define machine_id do |web| config.vm.define machine_id do |web|
web.vm.box = "ubuntu/focal64" web.vm.box = "ubuntu/focal64"
web.vm.hostname = machine_id web.vm.hostname = machine_id
web.vm.network "private_network", ip: increment_ip() web.vm.network "private_network", ip: machine_ip
web.vm.provision "file", source: "./.ssh/id_rsa.pub", destination: "~/.ssh/authorized_keys" web.vm.provision "file", source: "./.ssh/id_rsa.pub", destination: "~/.ssh/authorized_keys"
web.vm.provider "virtualbox" do |vb| web.vm.provider "virtualbox" do |vb|
@ -34,24 +44,27 @@ Vagrant.configure("2") do |config|
if nth == num_webserver if nth == num_webserver
config.vm.provision "ansible" do |ansible| config.vm.provision "ansible" do |ansible|
ansible.playbook = "./playbooks/install_nginx.yml" ansible.playbook = "./playbooks/install_nginx.yml"
ansible.groups = { ansible.groups = ansible_groups
"webserver" => webserver_ids ansible.host_vars = ansible_vars
}
end end
end end
end end
end end
lbserver_ids = []
(1..num_loadbalancer).each do |nth| (1..num_loadbalancer).each do |nth|
machine_id = "#{customerName}-bloated-debian-lb%d" % [nth] machine_id = "#{customerName}-bloated-debian-lb%d" % [nth]
lbserver_ids = lbserver_ids.push(machine_id) ansible_groups["loadbalancer"] << machine_id
machine_ip = increment_ip()
ansible_vars[machine_id] = {
"ipv4_address" => machine_ip
}
config.vm.define machine_id do |web| config.vm.define machine_id do |web|
web.vm.box = "ubuntu/focal64" web.vm.box = "ubuntu/focal64"
web.vm.hostname = machine_id web.vm.hostname = machine_id
web.vm.network "private_network", ip: increment_ip() web.vm.network "private_network", ip: machine_ip
web.vm.provision "file", source: "./.ssh/id_rsa.pub", destination: "~/.ssh/authorized_keys" web.vm.provision "file", source: "./.ssh/id_rsa.pub", destination: "~/.ssh/authorized_keys"
web.vm.provider "virtualbox" do |vb| web.vm.provider "virtualbox" do |vb|
@ -63,9 +76,8 @@ Vagrant.configure("2") do |config|
if nth == num_loadbalancer if nth == num_loadbalancer
config.vm.provision "ansible" do |ansible| config.vm.provision "ansible" do |ansible|
ansible.playbook = "./playbooks/install_loadbalancer.yml" ansible.playbook = "./playbooks/install_loadbalancer.yml"
ansible.groups = { ansible.groups = ansible_groups
"loadbalancer" => lbserver_ids ansible.host_vars = ansible_vars
}
end end
end end
end end