Add Vagrantfile

This commit is contained in:
Glenn Y. Rolland 2022-05-30 21:35:15 +02:00
parent 0994da378e
commit be88a70d70

93
Vagrantfile vendored
View file

@ -3,50 +3,101 @@
# frozen_string_literal: true # frozen_string_literal: true
SERVERS_COUNT=3 # Setup & rules
class Infra
GROUPS_COUNT = 1
REPLICAS_COUNT = 2
## Utilities
def self.gateway_name(index)
"dev-gateway#{index}"
end
def self.mongo_name(index)
"dev-server#{index}"
end
def self.gateway_ip(index)
"192.168.50.#{250 - index * 5}"
end
def self.server_ip(index)
"192.168.50.#{5 + index * 5}"
end
def self.role_mongo
Infra::REPLICAS_COUNT.times.map { |i| mongo_name(i) }
end
def self.role_gateway
Infra::GROUPS_COUNT.times.map { |i| gateway_name(i) }
end
end
##
## Vagrant configuration
##
# rubocop:disable Metrics/BlockLength
Vagrant.configure('2') do |config| Vagrant.configure('2') do |config|
# Common settings for virtual machines ##
## Common settings for virtual machines
##
config.vm.box = 'debian/bullseye64' config.vm.box = 'debian/bullseye64'
config.vm.box_check_update = false config.vm.box_check_update = false
## ##
## gateway: Guacamole proxy + entrypoint ## Web frontends
## ##
config.vm.define 'gateway' do |machine| Infra::GROUPS_COUNT.times do |index|
machine.vm.hostname = 'gateway' config.vm.define Infra.gateway_name(index) do |machine|
machine.vm.network 'private_network', ip: '192.168.50.250' machine.vm.hostname = Infra.gateway_name(index)
machine.vm.network 'forwarded_port', guest: 80, host: 1080 machine.vm.network 'private_network', ip: Infra.gateway_ip(index)
machine.vm.network 'forwarded_port', guest: 8080, host: 8080
machine.vm.provider 'virtualbox' do |vb| machine.vm.provider 'virtualbox' do |vb|
vb.memory = '4000' vb.memory = '4000'
vb.gui = false vb.gui = false
end end
next if index.positive? # strictly positive (not null)
# machine.vm.network 'forwarded_port', guest: 80, host: 1080
# machine.vm.network 'forwarded_port', guest: 8080, host: 8080
end
end end
## ##
## serverX : host servers with mongo, etc ## Mongo servers
## ##
server_ip = ->(index) { "192.168.50.#{10 + index * 10}" } (Infra::GROUPS_COUNT * Infra::REPLICAS_COUNT).times do |index|
SERVERS_COUNT.times do |index| config.vm.define Infra.mongo_name(index) do |machine|
config.vm.define "server#{index}" do |machine| machine.vm.hostname = Infra.mongo_name(index)
machine.vm.hostname = "server#{index}" machine.vm.network 'private_network', ip: Infra.server_ip(index)
machine.vm.network 'private_network', ip: server_ip.call(index)
machine.vm.provider 'virtualbox' do |vb| machine.vm.provider 'virtualbox' do |vb|
vb.memory = '3000' vb.memory = '3000'
vb.gui = false vb.gui = false
end end
end
end
config.vm.provision 'ansible' do |ansible| next if (index + 1) < (Infra::GROUPS_COUNT * Infra::REPLICAS_COUNT)
ansible.playbook = 'ansible/playbook.yml'
machine.vm.provision 'ansible' do |ansible|
# ansible.verbose = true # ansible.verbose = true
ansible.playbook = 'ansible/playbook.yml'
ansible.config_file = 'ansible/ansible.cfg' ansible.config_file = 'ansible/ansible.cfg'
ansible.limit = 'all'
ansible.groups = { ansible.groups = {
'app_sshwifty' => ['gateway'], 'role_gateway' => Infra.role_gateway,
'app_mongo' => SERVERS_COUNT.times.map { |i| "server#{i}" }, 'role_mongo' => Infra.role_mongo,
'all_groups:children' => ['app_mongo'] 'stage_development' => [Infra.role_mongo, Infra.role_gateway].flatten,
'stage_production' => [],
'stage_testing' => [],
'all_groups:children' => %w[role_gateway role_mongo],
'all:vars' => {
'mongo_groups_count' => Infra::GROUPS_COUNT,
'mongo_replicas_count' => Infra::REPLICAS_COUNT
}
} }
end end
end end
end
end
# rubocop:enable Metrics/BlockLength