Vagrantfile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. VAGRANTFILE_API_VERSION = "2"
  4. NETWORK = "192.168.56."
  5. NETMASK = "255.255.255.0"
  6. # Put the MAIN ip <-> NCDOM domain below to host /etc/hosts
  7. MAIN = NETWORK+"10"
  8. NCDOM = "nextcloud.test"
  9. # VM machines configuration
  10. # ip address of the vm is NETWORK plus the last part of the IP
  11. HOSTS = [
  12. #VM_NAME IP_ADDRESS RAM(mb) CPU BOX GROUP
  13. { :hostname => "db", :ip => NETWORK+"11", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "database_servers" },
  14. { :hostname => "redis", :ip => NETWORK+"21", :ram => 512, :cpu => 1, :box => "centos/7", :group => "redis_servers" }, #:folder_guest => "/srv/website", :folder_host => "src/" },
  15. #{ :hostname => "redis2", :ip => NETWORK+"22", :ram => 512, :cpu => 1, :box => "centos/7", :group => "redis_servers" }, #:port_guest => 80, :port_host => 8080 },
  16. { :hostname => "web", :ip => NETWORK+"31", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "web_servers" },
  17. #{ :hostname => "web2", :ip => NETWORK+"32", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "web_servers" },
  18. { :hostname => "lb", :ip => NETWORK+"41", :ram => 512, :cpu => 1, :box => "ubuntu/focal64", :group => "loadbalancer_servers" },
  19. #{ :hostname => "lb2", :ip => NETWORK+"42", :ram => 512, :cpu => 1, :box => "ubuntu/focal64", :group => "loadbalancer_servers" },
  20. ]
  21. # Defined ansible playbook
  22. # If empty, will skip the ansible provisioner block
  23. ansible_playbook = "provisioning/ansible/playbook.yml"
  24. # Ansible inventory. The path supports nested directories or a single file
  25. ansible_inventory_path = "provisioning/ansible/hosts"
  26. Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  27. if Vagrant.has_plugin?("vagrant-hostmanager")
  28. config.vm.box_check_update = false
  29. # To enable the hostmanager plugin
  30. config.hostmanager.enabled = true
  31. # To enable add records to host /etc/hosts
  32. config.hostmanager.manage_host = false
  33. # To enable add records to guest /etc/hosts
  34. config.hostmanager.manage_guest = true
  35. # Not use private ip addresses for the hosts file, set to false
  36. config.hostmanager.ignore_private_ip = false
  37. config.hostmanager.include_offline = false
  38. end
  39. # Create groups to be used in ansible inventory
  40. groups = {"all" => []}
  41. HOSTS.each do |cfg|
  42. if ! groups.has_key?(cfg[:group])
  43. groups[cfg[:group]] = [cfg[:hostname]]
  44. else
  45. #combi = cfg[:ip]+" server_name="+cfg[:hostname]
  46. #groups[cfg[:group]].push(combi)
  47. groups[cfg[:group]].push(cfg[:hostname])
  48. end
  49. #combi = cfg[:ip]+" server_name="+cfg[:hostname]
  50. #groups["all"].push(combi)
  51. groups["all"].push(cfg[:hostname])
  52. end
  53. # Create inventory for ansible provision
  54. # The inventory will hold servers details and groups per each server.
  55. if File.dirname(ansible_inventory_path) != "."
  56. Dir.mkdir(File.dirname(ansible_inventory_path)) unless Dir.exist?(File.dirname(ansible_inventory_path))
  57. end
  58. File.open(ansible_inventory_path, 'w') do |f|
  59. HOSTS.each do |cfg|
  60. f.write "#{cfg[:hostname]} ansible_host=#{cfg[:ip]}\n"
  61. end
  62. groups.keys.each do |g|
  63. f.write "\n"
  64. f.write "[#{g}]\n"
  65. groups[g].each do |h|
  66. f.write "#{h}\n"
  67. end
  68. end
  69. end
  70. # VM DEFINITIONS
  71. HOSTS.each_with_index do |server, index|
  72. config.vm.define server[:hostname] do |conf|
  73. conf.vm.box = server[:box]
  74. conf.vm.hostname = server[:hostname]
  75. conf.vm.boot_timeout = 360
  76. # Set system options
  77. cpu = server[:cpu] ? server[:cpu] : 1;
  78. memory = server[:ram] ? server[:ram] : 512;
  79. name = server[:hostname] ? server[:hostname] : "linux";
  80. conf.vm.provider "virtualbox" do |vbox|
  81. vbox.cpus = cpu.to_s
  82. vbox.memory = memory.to_s
  83. vbox.name = name
  84. end
  85. # Set network options
  86. netmask = server[:netmask] || NETMASK
  87. conf.vm.network :private_network, ip: server[:ip], netmask: netmask
  88. # Set port forwarding if defined
  89. if !server[:port_guest].nil? && !server[:port_host].nil?
  90. conf.vm.network "forwarded_port", guest: server[:port_guest], host: server[:port_host]
  91. end
  92. # Set synced folders if defined
  93. if !server[:folder_guest].nil? && !server[:folder_host].nil?
  94. conf.vm.synced_folder server[:folder_host], server[:folder_guest]
  95. end
  96. # Set common provision
  97. conf.vm.provision "shell" do |s|
  98. s.path = "provisioning/bash/common.sh"
  99. s.args = [server[:box]]
  100. end
  101. # Provision nodes with Ansible.
  102. # The index used here in order to execute the provision just after all
  103. # the servers are up and running.
  104. #if index == HOSTS.size - 1
  105. # if ansible_playbook != ""
  106. # conf.vm.provision :ansible do |ansible|
  107. # ansible.limit = "all"
  108. # ansible.compatibility_mode = "2.0"
  109. # ansible.become = true
  110. # ansible.inventory_path = ansible_inventory_path
  111. # ansible.playbook = ansible_playbook
  112. # #ansible.verbose = "vvvv"
  113. # end
  114. #end
  115. end
  116. end
  117. # VM PROVISIONING
  118. #Database Server
  119. config.vm.define "db" do |db|
  120. # Temp NFS stuff waiting Ceph
  121. db.vm.provision "shell", path: "provisioning/bash/nfs-server.sh"
  122. #
  123. db.vm.provision "ansible" do |ansible|
  124. ansible.compatibility_mode = "2.0"
  125. ansible.playbook="provisioning/ansible/mariadb.yml"
  126. ansible.inventory_path = ansible_inventory_path
  127. ansible.become = true
  128. ansible.extra_vars = {
  129. db_users: [
  130. { name: 'web', password: 'secret', host: 'web' },
  131. { name: 'web', password: 'secret', host: 'web2' }
  132. ]
  133. }
  134. end
  135. end
  136. #Redis Server
  137. config.vm.define "redis" do |redis|
  138. redis.vm.provision :ansible do |ansible|
  139. ansible.compatibility_mode = "2.0"
  140. ansible.playbook="provisioning/ansible/redis.yml"
  141. ansible.inventory_path = ansible_inventory_path
  142. ansible.become = true
  143. #ansible.extra_vars = {
  144. # #redis_bind_interface: "192.168.56.14", #bug Centos
  145. #}
  146. end
  147. end
  148. # #Web Server
  149. config.vm.define "web" do |web|
  150. web.vm.provision "shell", path: "provisioning/bash/Centos_7.sh"
  151. web.vm.provision "ansible" do |ansible|
  152. ansible.compatibility_mode = "2.0"
  153. ansible.playbook = "provisioning/ansible/nextcloud.yml"
  154. ansible.inventory_path = ansible_inventory_path
  155. ansible.become = true
  156. ansible.extra_vars = {
  157. ssl_name: NCDOM,
  158. nc_trusted_domain: "web",
  159. db_host: "db",
  160. nc_db_user: "web",
  161. nc_db_password: "secret",
  162. use_redis_server: "true",
  163. redis_host: "redis",
  164. #nc_multiple: "nfs",
  165. #nfs_server: "db",
  166. }
  167. #ansible.verbose = "vvvv"
  168. end
  169. end
  170. # #LoadBalancer (master)
  171. config.vm.define "lb" do |lb|
  172. lb.vm.provision "ansible" do |ansible|
  173. ansible.compatibility_mode = "2.0"
  174. ansible.playbook="provisioning/ansible/haproxy.yml"
  175. ansible.inventory_path = ansible_inventory_path
  176. ansible.become = true
  177. ansible.extra_vars = {
  178. ssl_name: NCDOM,
  179. network_allowed: NETWORK+"0/24",
  180. keepalived_vip: MAIN,
  181. keepalived_priority: 101,
  182. keepalived_state: "MASTER",
  183. haproxy_backend_servers: [
  184. { name: 'web', ip: 'web:8000' },
  185. #{ name: 'web2', ip: 'web2:8000' }
  186. ]
  187. }
  188. end
  189. end
  190. # #LoadBalancer (backup)
  191. # config.vm.define "lb2" do |lb2|
  192. # lb2.vm.provision "shell", inline: "apt-get install -y haproxy keepalived"
  193. # lb2.vm.provision "ansible" do |ansible|
  194. # ansible.compatibility_mode = "2.0"
  195. # ansible.playbook="provisioning/ansible/haproxy.yml"
  196. # ansible.become = true
  197. # ansible.extra_vars = {
  198. # ansible_python_interpreter: "/usr/bin/python3",
  199. # ssl_name: NCDOM,
  200. # network_allowed: NETWORK+"0/24",
  201. # keepalived_vip: MAIN,
  202. # keepalived_priority: 100,
  203. # keepalived_state: "BACKUP",
  204. # haproxy_backend_servers: [
  205. # { name: 'web', ip: 'web:8000' },
  206. # #{ name: 'web2', ip: 'web2:8000' }
  207. # ]
  208. # }
  209. # end
  210. # end
  211. #
  212. # #Web Server 2
  213. # config.vm.define "web2" do |web2|
  214. # web2.vm.hostname = "nextcloud"
  215. # web2.vm.box = "centos/7"
  216. # web2.vm.network "private_network", ip: "192.168.56.15"
  217. #
  218. # web2.vm.provision "shell", path: "provisioning/install/Centos_7.sh"
  219. # web2.vm.provision "ansible" do |ansible|
  220. # ansible.compatibility_mode = "2.0"
  221. # ansible.playbook = "provisioning/ansible/nextcloud.yml"
  222. # ansible.become = true
  223. # ansible.extra_vars = {
  224. # ansible_python_interpreter: "/usr/bin/python2",
  225. # ssl_name: "nextcloud.test",
  226. # nc_trusted_domain: "192.168.56.15",
  227. # db_host: "192.168.56.21",
  228. # nc_db_user: "web",
  229. # nc_db_password: "secret",
  230. # use_redis_server: "true",
  231. # redis_host: "192.168.56.13",
  232. # #nc_multiple: "nfs",
  233. # #nfs_server: "192.168.56.21",
  234. # }
  235. # #ansible.inventory_path = "provisioning/apache.inventory"
  236. # #ansible.verbose = "vvvv"
  237. # end
  238. # end
  239. #
  240. # #Prometheus
  241. # config.vm.define "prometheus" do |prometheus|
  242. # prometheus.vm.box = 'centos/7'
  243. # prometheus.vm.hostname = "prometheus"
  244. # prometheus.vm.network :private_network, ip: "192.168.56.41"
  245. # prometheus.vm.provision "shell", path: "provisioning/install/Centos_7.sh"
  246. #
  247. # #Provision prometheus-grafana with Ansible
  248. # prometheus.vm.provision "ansible" do |ansible|
  249. # ansible.compatibility_mode = "2.0"
  250. # ansible.playbook="provisioning/ansible/prometheus.yml"
  251. # ansible.become = true
  252. # ansible.extra_vars = {
  253. # ansible_python_interpreter: "/usr/bin/python2",
  254. # }
  255. # end
  256. # end
  257. #
  258. # #Node Exporter
  259. # config.vm.define "node" do |node|
  260. # node.vm.box = 'centos/7'
  261. # node.vm.hostname = "nodexporter"
  262. # node.vm.network :private_network, ip: "192.168.56.42"
  263. # node.vm.provision "shell", path: "provisioning/install/Centos_7.sh"
  264. #
  265. # #Provision prometheus-grafana with Ansible
  266. # node.vm.provision "ansible" do |ansible|
  267. # ansible.compatibility_mode = "2.0"
  268. # ansible.playbook="provisioning/ansible/node_exporter.yml"
  269. # ansible.become = true
  270. # ansible.extra_vars = {
  271. # ansible_python_interpreter: "/usr/bin/python2",
  272. # }
  273. # end
  274. # end
  275. #
  276. # #Grafana
  277. # config.vm.define "grafana" do |grafana|
  278. # grafana.vm.box = 'centos/7'
  279. # grafana.vm.hostname = "grafana"
  280. # grafana.vm.network :private_network, ip: "192.168.56.43"
  281. # grafana.vm.provision "shell", path: "provisioning/install/Centos_7.sh"
  282. #
  283. # #Provision prometheus-grafana with Ansible
  284. # grafana.vm.provision "ansible" do |ansible|
  285. # ansible.compatibility_mode = "2.0"
  286. # ansible.playbook="provisioning/ansible/grafana.yml"
  287. # ansible.become = true
  288. # ansible.extra_vars = {
  289. # ansible_python_interpreter: "/usr/bin/python2",
  290. # }
  291. # end
  292. # end
  293. #end
  294. end