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_loadbalancer = #{numLoadbalancers}
webserver_ids = []
ansible_groups = {
"loadbalancer" => [],
"webserver" => []
}
ansible_vars = {}
(1..num_webserver).each do |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|
web.vm.box = "ubuntu/focal64"
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.provider "virtualbox" do |vb|
@ -34,24 +44,27 @@ Vagrant.configure("2") do |config|
if nth == num_webserver
config.vm.provision "ansible" do |ansible|
ansible.playbook = "./playbooks/install_nginx.yml"
ansible.groups = {
"webserver" => webserver_ids
}
ansible.groups = ansible_groups
ansible.host_vars = ansible_vars
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)
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.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.provider "virtualbox" do |vb|
@ -63,9 +76,8 @@ Vagrant.configure("2") do |config|
if nth == num_loadbalancer
config.vm.provision "ansible" do |ansible|
ansible.playbook = "./playbooks/install_loadbalancer.yml"
ansible.groups = {
"loadbalancer" => lbserver_ids
}
ansible.groups = ansible_groups
ansible.host_vars = ansible_vars
end
end
end