123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- # -*- mode: ruby -*-
- # vi: set ft=ruby :
- VAGRANTFILE_API_VERSION = "2"
- NETWORK = "192.168.56."
- NETMASK = "255.255.255.0"
- # Put the MAIN ip <-> NCDOM domain below to host /etc/hosts
- MAIN = NETWORK+"10"
- NCDOM = "nextcloud.test"
- # VM machines configuration
- # ip address of the vm is NETWORK plus the last part of the IP
- HOSTS = [
- #VM_NAME IP_ADDRESS RAM(mb) CPU BOX GROUP
- { :hostname => "db", :ip => NETWORK+"11", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "database_servers" },
- { :hostname => "redis", :ip => NETWORK+"21", :ram => 512, :cpu => 1, :box => "centos/7", :group => "redis_servers" }, #:folder_guest => "/srv/website", :folder_host => "src/" },
- #{ :hostname => "redis2", :ip => NETWORK+"22", :ram => 512, :cpu => 1, :box => "centos/7", :group => "redis_servers" }, #:port_guest => 80, :port_host => 8080 },
- { :hostname => "web", :ip => NETWORK+"31", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "web_servers" },
- #{ :hostname => "web2", :ip => NETWORK+"32", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "web_servers" },
- { :hostname => "lb", :ip => NETWORK+"41", :ram => 512, :cpu => 1, :box => "ubuntu/focal64", :group => "loadbalancer_servers" },
- #{ :hostname => "lb2", :ip => NETWORK+"42", :ram => 512, :cpu => 1, :box => "ubuntu/focal64", :group => "loadbalancer_servers" },
- ]
- # Defined ansible playbook
- # If empty, will skip the ansible provisioner block
- ansible_playbook = "provisioning/ansible/playbook.yml"
- # Ansible inventory. The path supports nested directories or a single file
- ansible_inventory_path = "provisioning/ansible/hosts"
- Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
- if Vagrant.has_plugin?("vagrant-hostmanager")
- config.vm.box_check_update = false
- # To enable the hostmanager plugin
- config.hostmanager.enabled = true
- # To enable add records to host /etc/hosts
- config.hostmanager.manage_host = false
- # To enable add records to guest /etc/hosts
- config.hostmanager.manage_guest = true
- # Not use private ip addresses for the hosts file, set to false
- config.hostmanager.ignore_private_ip = false
- config.hostmanager.include_offline = false
- end
- # Create groups to be used in ansible inventory
- groups = {"all" => []}
- HOSTS.each do |cfg|
- if ! groups.has_key?(cfg[:group])
- groups[cfg[:group]] = [cfg[:hostname]]
- else
- #combi = cfg[:ip]+" server_name="+cfg[:hostname]
- #groups[cfg[:group]].push(combi)
- groups[cfg[:group]].push(cfg[:hostname])
- end
- #combi = cfg[:ip]+" server_name="+cfg[:hostname]
- #groups["all"].push(combi)
- groups["all"].push(cfg[:hostname])
- end
- # Create inventory for ansible provision
- # The inventory will hold servers details and groups per each server.
- if File.dirname(ansible_inventory_path) != "."
- Dir.mkdir(File.dirname(ansible_inventory_path)) unless Dir.exist?(File.dirname(ansible_inventory_path))
- end
- File.open(ansible_inventory_path, 'w') do |f|
- HOSTS.each do |cfg|
- f.write "#{cfg[:hostname]} ansible_host=#{cfg[:ip]}\n"
- end
- groups.keys.each do |g|
- f.write "\n"
- f.write "[#{g}]\n"
- groups[g].each do |h|
- f.write "#{h}\n"
- end
- end
- end
- # VM DEFINITIONS
- HOSTS.each_with_index do |server, index|
- config.vm.define server[:hostname] do |conf|
- conf.vm.box = server[:box]
- conf.vm.hostname = server[:hostname]
- conf.vm.boot_timeout = 360
- # Set system options
- cpu = server[:cpu] ? server[:cpu] : 1;
- memory = server[:ram] ? server[:ram] : 512;
- name = server[:hostname] ? server[:hostname] : "linux";
- conf.vm.provider "virtualbox" do |vbox|
- vbox.cpus = cpu.to_s
- vbox.memory = memory.to_s
- vbox.name = name
- end
- # Set network options
- netmask = server[:netmask] || NETMASK
- conf.vm.network :private_network, ip: server[:ip], netmask: netmask
- # Set port forwarding if defined
- if !server[:port_guest].nil? && !server[:port_host].nil?
- conf.vm.network "forwarded_port", guest: server[:port_guest], host: server[:port_host]
- end
- # Set synced folders if defined
- if !server[:folder_guest].nil? && !server[:folder_host].nil?
- conf.vm.synced_folder server[:folder_host], server[:folder_guest]
- end
- # Set common provision
- conf.vm.provision "shell" do |s|
- s.path = "provisioning/bash/common.sh"
- s.args = [server[:box]]
- end
- # Provision nodes with Ansible.
- # The index used here in order to execute the provision just after all
- # the servers are up and running.
- #if index == HOSTS.size - 1
- # if ansible_playbook != ""
- # conf.vm.provision :ansible do |ansible|
- # ansible.limit = "all"
- # ansible.compatibility_mode = "2.0"
- # ansible.become = true
- # ansible.inventory_path = ansible_inventory_path
- # ansible.playbook = ansible_playbook
- # #ansible.verbose = "vvvv"
- # end
- #end
- end
- end
- # VM PROVISIONING
- #Database Server
- config.vm.define "db" do |db|
- # Temp NFS stuff waiting Ceph
- db.vm.provision "shell", path: "provisioning/bash/nfs-server.sh"
- #
- db.vm.provision "ansible" do |ansible|
- ansible.compatibility_mode = "2.0"
- ansible.playbook="provisioning/ansible/mariadb.yml"
- ansible.inventory_path = ansible_inventory_path
- ansible.become = true
- ansible.extra_vars = {
- db_users: [
- { name: 'web', password: 'secret', host: 'web' },
- { name: 'web', password: 'secret', host: 'web2' }
- ]
- }
- end
- end
- #Redis Server
- config.vm.define "redis" do |redis|
- redis.vm.provision :ansible do |ansible|
- ansible.compatibility_mode = "2.0"
- ansible.playbook="provisioning/ansible/redis.yml"
- ansible.inventory_path = ansible_inventory_path
- ansible.become = true
- #ansible.extra_vars = {
- # #redis_bind_interface: "192.168.56.14", #bug Centos
- #}
- end
- end
- # #Web Server
- config.vm.define "web" do |web|
- web.vm.provision "shell", path: "provisioning/bash/Centos_7.sh"
- web.vm.provision "ansible" do |ansible|
- ansible.compatibility_mode = "2.0"
- ansible.playbook = "provisioning/ansible/nextcloud.yml"
- ansible.inventory_path = ansible_inventory_path
- ansible.become = true
- ansible.extra_vars = {
- ssl_name: NCDOM,
- nc_trusted_domain: "web",
- db_host: "db",
- nc_db_user: "web",
- nc_db_password: "secret",
- use_redis_server: "true",
- redis_host: "redis",
- #nc_multiple: "nfs",
- #nfs_server: "db",
- }
- #ansible.verbose = "vvvv"
- end
- end
- # #LoadBalancer (master)
- config.vm.define "lb" do |lb|
- lb.vm.provision "ansible" do |ansible|
- ansible.compatibility_mode = "2.0"
- ansible.playbook="provisioning/ansible/haproxy.yml"
- ansible.inventory_path = ansible_inventory_path
- ansible.become = true
- ansible.extra_vars = {
- ssl_name: NCDOM,
- network_allowed: NETWORK+"0/24",
- keepalived_vip: MAIN,
- keepalived_priority: 101,
- keepalived_state: "MASTER",
- haproxy_backend_servers: [
- { name: 'web', ip: 'web:8000' },
- #{ name: 'web2', ip: 'web2:8000' }
- ]
- }
- end
- end
- # #LoadBalancer (backup)
- # config.vm.define "lb2" do |lb2|
- # lb2.vm.provision "shell", inline: "apt-get install -y haproxy keepalived"
- # lb2.vm.provision "ansible" do |ansible|
- # ansible.compatibility_mode = "2.0"
- # ansible.playbook="provisioning/ansible/haproxy.yml"
- # ansible.become = true
- # ansible.extra_vars = {
- # ansible_python_interpreter: "/usr/bin/python3",
- # ssl_name: NCDOM,
- # network_allowed: NETWORK+"0/24",
- # keepalived_vip: MAIN,
- # keepalived_priority: 100,
- # keepalived_state: "BACKUP",
- # haproxy_backend_servers: [
- # { name: 'web', ip: 'web:8000' },
- # #{ name: 'web2', ip: 'web2:8000' }
- # ]
- # }
- # end
- # end
- #
- # #Web Server 2
- # config.vm.define "web2" do |web2|
- # web2.vm.hostname = "nextcloud"
- # web2.vm.box = "centos/7"
- # web2.vm.network "private_network", ip: "192.168.56.15"
- #
- # web2.vm.provision "shell", path: "provisioning/install/Centos_7.sh"
- # web2.vm.provision "ansible" do |ansible|
- # ansible.compatibility_mode = "2.0"
- # ansible.playbook = "provisioning/ansible/nextcloud.yml"
- # ansible.become = true
- # ansible.extra_vars = {
- # ansible_python_interpreter: "/usr/bin/python2",
- # ssl_name: "nextcloud.test",
- # nc_trusted_domain: "192.168.56.15",
- # db_host: "192.168.56.21",
- # nc_db_user: "web",
- # nc_db_password: "secret",
- # use_redis_server: "true",
- # redis_host: "192.168.56.13",
- # #nc_multiple: "nfs",
- # #nfs_server: "192.168.56.21",
- # }
- # #ansible.inventory_path = "provisioning/apache.inventory"
- # #ansible.verbose = "vvvv"
- # end
- # end
- #
- # #Prometheus
- # config.vm.define "prometheus" do |prometheus|
- # prometheus.vm.box = 'centos/7'
- # prometheus.vm.hostname = "prometheus"
- # prometheus.vm.network :private_network, ip: "192.168.56.41"
- # prometheus.vm.provision "shell", path: "provisioning/install/Centos_7.sh"
- #
- # #Provision prometheus-grafana with Ansible
- # prometheus.vm.provision "ansible" do |ansible|
- # ansible.compatibility_mode = "2.0"
- # ansible.playbook="provisioning/ansible/prometheus.yml"
- # ansible.become = true
- # ansible.extra_vars = {
- # ansible_python_interpreter: "/usr/bin/python2",
- # }
- # end
- # end
- #
- # #Node Exporter
- # config.vm.define "node" do |node|
- # node.vm.box = 'centos/7'
- # node.vm.hostname = "nodexporter"
- # node.vm.network :private_network, ip: "192.168.56.42"
- # node.vm.provision "shell", path: "provisioning/install/Centos_7.sh"
- #
- # #Provision prometheus-grafana with Ansible
- # node.vm.provision "ansible" do |ansible|
- # ansible.compatibility_mode = "2.0"
- # ansible.playbook="provisioning/ansible/node_exporter.yml"
- # ansible.become = true
- # ansible.extra_vars = {
- # ansible_python_interpreter: "/usr/bin/python2",
- # }
- # end
- # end
- #
- # #Grafana
- # config.vm.define "grafana" do |grafana|
- # grafana.vm.box = 'centos/7'
- # grafana.vm.hostname = "grafana"
- # grafana.vm.network :private_network, ip: "192.168.56.43"
- # grafana.vm.provision "shell", path: "provisioning/install/Centos_7.sh"
- #
- # #Provision prometheus-grafana with Ansible
- # grafana.vm.provision "ansible" do |ansible|
- # ansible.compatibility_mode = "2.0"
- # ansible.playbook="provisioning/ansible/grafana.yml"
- # ansible.become = true
- # ansible.extra_vars = {
- # ansible_python_interpreter: "/usr/bin/python2",
- # }
- # end
- # end
- #end
- end
|