infra-as-code/templates/Vagrantfile.template

81 lines
2.3 KiB
Plaintext

$ip_int = {{ ip_int }}
def increment_ip()
ip = "{{ ip_format }}" % [$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"]
num_postgresql = {{ num_postgres }}
{% if webserver_specs is not none %}
(1..{{ num_webserver }}).each do |nth|
machine_id = "{{ customer_name }}-{{ env }}-web%d" % [nth]
machine_ip = increment_ip()
config.vm.define machine_id do |web|
web.vm.box = "ubuntu/focal64"
web.vm.hostname = machine_id
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|
vb.memory = {{ webserver_specs["mem"] }}
vb.cpus = {{ webserver_specs["cpus"] }}
vb.gui = false
vb.name = machine_id
end
end
end
{% endif %}
{% if loadbalancers_specs is not none %}
(1..{{ num_loadbalancers }}).each do |nth|
machine_id = "{{ customer_name }}-{{ env }}-lb%d" % [nth]
machine_ip = increment_ip()
config.vm.define machine_id do |web|
web.vm.box = "ubuntu/focal64"
web.vm.hostname = machine_id
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|
vb.memory = {{ loadbalancers_specs["mem"] }}
vb.cpus = {{ loadbalancers_specs["cpus"] }}
vb.gui = false
vb.name = machine_id
end
end
end
{% endif %}
{% if postgres_specs is not none %}
(1..{{ num_postgres }}).each do |nth|
machine_id = "{{ customer_name }}-{{ env }}-db%d" % [nth]
machine_ip = increment_ip()
config.vm.define machine_id do |web|
web.vm.box = "ubuntu/focal64"
web.vm.hostname = machine_id
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|
vb.memory = {{ postgres_specs["mem"] }}
vb.cpus = {{ postgres_specs["cpus"] }}
vb.gui = false
vb.name = machine_id
end
end
end
{% endif %}
end