|
@@ -3,112 +3,262 @@
|
|
|
|
|
|
VAGRANTFILE_API_VERSION = "2"
|
|
|
|
|
|
-Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|
|
+NETWORK = "192.168.56."
|
|
|
+NETMASK = "255.255.255.0"
|
|
|
|
|
|
- config.vm.boot_timeout = 360
|
|
|
- #config.ssh.insert_key = false
|
|
|
- #config.ssh.username = "vagrant"
|
|
|
- #config.ssh.password = "vagrant"
|
|
|
+# Put the MAIN ip <-> NCDOM domain below to host /etc/hosts
|
|
|
+MAIN = NETWORK+"10"
|
|
|
+NCDOM = "nextcloud.test"
|
|
|
|
|
|
- config.vm.provider "virtualbox" do |vb|
|
|
|
- vb.memory = "1024"
|
|
|
- vb.cpus = "1"
|
|
|
- end
|
|
|
+# 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" },
|
|
|
+]
|
|
|
|
|
|
- #LoadBalancer
|
|
|
- config.vm.define "loadbalancer" do |loadbalancer|
|
|
|
- loadbalancer.vm.box = 'ubuntu/focal64'
|
|
|
- loadbalancer.vm.hostname = "loadbalancer"
|
|
|
- loadbalancer.vm.network :private_network, ip: "192.168.56.10"
|
|
|
- loadbalancer.vm.provision "shell", inline: "apt-get install -y haproxy"
|
|
|
+# 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"
|
|
|
|
|
|
- #Provision the loadbalancer with Ansible
|
|
|
- loadbalancer.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: "nextcloud.test",
|
|
|
- network_allowed: "192.168.56.0/24",
|
|
|
- haproxy_backend_servers:
|
|
|
- { name: 'web', ip: '192.168.56.14:8000' },
|
|
|
- }
|
|
|
+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
|
|
|
|
|
|
- #Redis Server
|
|
|
- config.vm.define "redis" do |redis|
|
|
|
- redis.vm.hostname = "redis"
|
|
|
- redis.vm.box = "centos/7"
|
|
|
- redis.vm.network "private_network", ip: "192.168.56.12"
|
|
|
- redis.vm.provision "shell", inline: "yum install -y python3 dnf epel-release"
|
|
|
-
|
|
|
- #Provision the webserver with Ansible
|
|
|
- redis.vm.provision "ansible" do |ansible|
|
|
|
- ansible.compatibility_mode = "2.0"
|
|
|
- ansible.playbook="provisioning/ansible/redis.yml"
|
|
|
- ansible.become = true
|
|
|
- ansible.extra_vars = {
|
|
|
- ansible_python_interpreter: "/usr/bin/python2",
|
|
|
- #redis_bind_interface: "192.168.56.14", #bug Centos
|
|
|
- }
|
|
|
- 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
|
|
|
|
|
|
- #Database Server
|
|
|
- config.vm.define "db" do |db|
|
|
|
- db.vm.hostname = "mariadb"
|
|
|
- db.vm.box = "centos/7"
|
|
|
- db.vm.network "private_network", ip: "192.168.56.13"
|
|
|
- db.vm.provision "shell", inline: "yum install -y python3 dnf"
|
|
|
+ # VM DEFINITIONS
|
|
|
|
|
|
- #Provision the webserver with Ansible
|
|
|
- db.vm.provision "ansible" do |ansible|
|
|
|
- ansible.compatibility_mode = "2.0"
|
|
|
- ansible.playbook="provisioning/ansible/mariadb.yml"
|
|
|
- ansible.become = true
|
|
|
- ansible.extra_vars = {
|
|
|
- ansible_python_interpreter: "/usr/bin/python2",
|
|
|
- app_bind_address: "192.168.56.14"
|
|
|
- }
|
|
|
+ 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
|
|
|
|
|
|
- #Web Server
|
|
|
- config.vm.define "web" do |web|
|
|
|
- web.vm.hostname = "nextcloud"
|
|
|
- web.vm.box = "centos/7"
|
|
|
- web.vm.network "private_network", ip: "192.168.56.14"
|
|
|
+ # VM PROVISIONING
|
|
|
|
|
|
- # Creating a Shared Directory between host and guest VM
|
|
|
- #web.vm.synced_folder "/apps/shared", "/shared"
|
|
|
+ #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
|
|
|
|
|
|
- #Provision the webserver for nextcloud role ansible
|
|
|
- web.vm.provision "shell", path: "provisioning/install/Centos_7.sh"
|
|
|
+ #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
|
|
|
|
|
|
- #Provision the webserver with Ansible
|
|
|
+ # #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 = {
|
|
|
- ansible_python_interpreter: "/usr/bin/python2",
|
|
|
- db_host: "192.168.56.13",
|
|
|
+ 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: "192.168.56.12",
|
|
|
- debug_speed: "false",
|
|
|
+ redis_host: "redis",
|
|
|
+ #nc_multiple: "nfs",
|
|
|
+ #nfs_server: "db",
|
|
|
}
|
|
|
- #ansible.inventory_path = "provisioning/apache.inventory"
|
|
|
#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.11"
|
|
|
+# 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
|
|
@@ -126,7 +276,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|
|
# config.vm.define "node" do |node|
|
|
|
# node.vm.box = 'centos/7'
|
|
|
# node.vm.hostname = "nodexporter"
|
|
|
-# node.vm.network :private_network, ip: "192.168.56.15"
|
|
|
+# 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
|
|
@@ -144,7 +294,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|
|
# config.vm.define "grafana" do |grafana|
|
|
|
# grafana.vm.box = 'centos/7'
|
|
|
# grafana.vm.hostname = "grafana"
|
|
|
-# grafana.vm.network :private_network, ip: "192.168.56.16"
|
|
|
+# 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
|
|
@@ -158,5 +308,5 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|
|
# end
|
|
|
# end
|
|
|
|
|
|
- config.vm.box_check_update = false
|
|
|
+ #end
|
|
|
end
|