Vagrantfile 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. HOSTS = [
  11. #VM_NAME IP_ADDRESS RAM(mb) CPU BOX GROUP
  12. #{ :hostname => "db1", :ip => NETWORK+"11", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "db_servers" }, #:guestport => 3306, :hostport => 13306 }, #:user => "" :pass => "" },
  13. #{ :hostname => "db2", :ip => NETWORK+"12", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "db_servers" }, #:guestport => 3306, :hostport => 23306 }, #:user => "" :pass => "" },
  14. #{ :hostname => "db3", :ip => NETWORK+"13", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "db_servers" }, #:guestport => 3306, :hostport => 33306 }, #:user => "" :pass => "" },
  15. #{ :hostname => "lbsql1", :ip => NETWORK+"19", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "db_lbal_servers", :state => "MASTER", :priority => 101, :vip => NETWORK+"20" },
  16. #{ :hostname => "lbsql2", :ip => NETWORK+"18", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "db_lbal_servers", :state => "BACKUP", :priority => 100, :vip => NETWORK+"20" },
  17. #{ :hostname => "redis", :ip => NETWORK+"21", :ram => 512, :cpu => 1, :box => "centos/7", :group => "redis_servers" },
  18. #{ :hostname => "redis2", :ip => NETWORK+"22", :ram => 512, :cpu => 1, :box => "centos/7", :group => "redis_servers" },
  19. #{ :hostname => "gl", :ip => NETWORK+"31", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "gluster_servers" },
  20. #{ :hostname => "gl2", :ip => NETWORK+"32", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "gluster_servers" },
  21. #{ :hostname => "web.test", :ip => NETWORK+"41", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "web_servers", :ipdb => NETWORK+"20" }, #:redisd => "keydb", :redisp => "6380", :redisv => NETWORK+"40", :priority => 101 },
  22. #{ :hostname => "web2.test", :ip => NETWORK+"42", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "web_servers", :ipdb => NETWORK+"20" }, #:redisd => "keydb", :redisp => "6380", :redisv => NETWORK+"40", :priority => 100 },
  23. #{ :hostname => "lb.test", :ip => NETWORK+"51", :ram => 1024, :cpu => 1, :box => "ubuntu/focal64", :group => "lbal_servers", :state => "MASTER", :priority => 101 },
  24. #{ :hostname => "lb2.test", :ip => NETWORK+"52", :ram => 1024, :cpu => 1, :box => "ubuntu/focal64", :group => "lbal_servers", :state => "BACKUP", :priority => 100 },
  25. #{ :hostname => "prome", :ip => NETWORK+"61", :ram => 512, :cpu => 1, :box => "centos/7", :group => "monitor_servers" },
  26. #{ :hostname => "node", :ip => NETWORK+"62", :ram => 512, :cpu => 1, :box => "centos/7", :group => "monitor_servers" },
  27. #{ :hostname => "grafa", :ip => NETWORK+"63", :ram => 512, :cpu => 1, :box => "centos/7", :group => "monitor_servers" },
  28. #{ :hostname => "essai1.test", :ip => NETWORK+"98", :ram => 1024, :cpu => 1, :box => "rockylinux/8", :group => "test_servers", :priority => 101, :vip => NETWORK+"100" },
  29. #{ :hostname => "essai2.test", :ip => NETWORK+"99", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "test_servers", :priority => 100, :vip => NETWORK+"100" },
  30. #{ :hostname => "essai.test", :ip => NETWORK+"98", :ram => 1024, :cpu => 1, :box => "rockylinux/8", :group => "test_servers" },
  31. #{ :hostname => "web.test", :ip => NETWORK+"41", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "web_servers" },
  32. #{ :hostname => "web2.test", :ip => NETWORK+"42", :ram => 1024, :cpu => 1, :box => "centos/7", :group => "web_servers" },
  33. ]
  34. HOSTS = [
  35. #{ :hostname => "db1", :ip => NETWORK+"11", :ram => 2048, :cpu => 1, :box => "rockylinux/8", :group => "db_servers", :synced_folder => "/backup/pelican/backup"},
  36. { :hostname => "db1", :ip => NETWORK+"11", :ram => 3072, :cpu => 1, :box => "rockylinux/8", :group => "db_servers" },
  37. #{ :hostname => "db2", :ip => NETWORK+"12", :ram => 2048, :cpu => 1, :box => "rockylinux/8", :group => "db_servers" },
  38. #{ :hostname => "db3", :ip => NETWORK+"13", :ram => 2048, :cpu => 1, :box => "rockylinux/8", :group => "db_servers" },
  39. #{ :hostname => "lbsql1", :ip => NETWORK+"19", :ram => 1024, :cpu => 1, :box => "rockylinux/8", :group => "db_lbal_servers", :state => "MASTER", :priority => 101, :vip => NETWORK+"20" },
  40. #{ :hostname => "lbsql2", :ip => NETWORK+"18", :ram => 1024, :cpu => 1, :box => "rockylinux/8", :group => "db_lbal_servers", :state => "BACKUP", :priority => 100, :vip => NETWORK+"20" },
  41. #{ :hostname => "gl1", :ip => NETWORK+"31", :ram => 1024, :cpu => 1, :box => "rockylinux/8", :group => "gluster_servers" },
  42. #{ :hostname => "gl2", :ip => NETWORK+"32", :ram => 1024, :cpu => 1, :box => "rockylinux/8", :group => "gluster_servers" },
  43. #{ :hostname => "ceph1", :ip => NETWORK+"71", :ram => 3072, :cpu => 2, :box => "ubuntu/focal64", :group => "ceph_servers", :disk_extra => "600GB", :disk_name => "ceph_storage_extra" },
  44. #{ :hostname => "ceph2", :ip => NETWORK+"72", :ram => 2048, :cpu => 1, :box => "ubuntu/focal64", :group => "ceph_servers", :disk_extra => "600GB", :disk_name => "ceph_storage" },
  45. #{ :hostname => "ceph3", :ip => NETWORK+"73", :ram => 2048, :cpu => 1, :box => "ubuntu/focal64", :group => "ceph_servers", :disk_extra => "600GB", :disk_name => "ceph_storage" },
  46. { :hostname => "ceph1", :ip => NETWORK+"71", :ram => 3072, :cpu => 2, :box => "rockylinux/8", :group => "ceph_servers" },
  47. { :hostname => "ceph2", :ip => NETWORK+"72", :ram => 3072, :cpu => 2, :box => "rockylinux/8", :group => "ceph_servers" },
  48. { :hostname => "ceph3", :ip => NETWORK+"73", :ram => 3072, :cpu => 2, :box => "rockylinux/8", :group => "ceph_servers" },
  49. #{ :hostname => "web.test", :ip => NETWORK+"41", :ram => 2048, :cpu => 1, :box => "rockylinux/8", :group => "web_servers", :synced_folder => "/backup/pelican"},
  50. { :hostname => "web.test", :ip => NETWORK+"41", :ram => 3072, :cpu => 2, :box => "rockylinux/8", :group => "web_servers" },
  51. #{ :hostname => "web.test", :ip => NETWORK+"41", :ram => 1024, :cpu => 1, :box => "rockylinux/8", :group => "web_servers", :ipdb => NETWORK+"20", :redisd => "keydb", :redisp => "6380", :redisv => NETWORK+"40", :priority => 101 },
  52. #{ :hostname => "web2.test", :ip => NETWORK+"42", :ram => 1024, :cpu => 1, :box => "rockylinux/8", :group => "web_servers", :ipdb => NETWORK+"20", :redisd => "keydb", :redisp => "6380", :redisv => NETWORK+"40", :priority => 100 },
  53. #{ :hostname => "lb.test", :ip => NETWORK+"51", :ram => 1024, :cpu => 1, :box => "rockylinux/8", :group => "lbal_servers" },
  54. ]
  55. # Defined ansible playbook
  56. vagrant_root = File.expand_path(File.dirname(__FILE__))
  57. # If empty, will skip the ansible provisioner block
  58. ansible_playbook = "provisioning/ansible/playbook.yml"
  59. # Ansible inventory. The path supports nested directories or a single file
  60. ansible_inventory_path = "provisioning/ansible/hosts"
  61. Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  62. if Vagrant.has_plugin?("vagrant-hostmanager")
  63. config.vm.box_check_update = false
  64. # To enable the hostmanager plugin
  65. config.hostmanager.enabled = true
  66. # To enable add records to host /etc/hosts
  67. config.hostmanager.manage_host = false
  68. # To enable add records to guest /etc/hosts
  69. config.hostmanager.manage_guest = true
  70. # Not use private ip addresses for the hosts file, set to false
  71. config.hostmanager.ignore_private_ip = false
  72. config.hostmanager.include_offline = false
  73. end
  74. # Create groups to be used in ansible inventory
  75. groups = {"all" => []}
  76. HOSTS.each do |cfg|
  77. if ! groups.has_key?(cfg[:group])
  78. groups[cfg[:group]] = [cfg[:hostname]]
  79. else
  80. groups[cfg[:group]].push(cfg[:hostname])
  81. end
  82. groups["all"].push(cfg[:hostname])
  83. end
  84. # Create inventory for ansible provision
  85. # The inventory will hold servers details and groups per each server.
  86. if File.dirname(ansible_inventory_path) != "."
  87. Dir.mkdir(File.dirname(ansible_inventory_path)) unless Dir.exist?(File.dirname(ansible_inventory_path))
  88. end
  89. File.delete(ansible_inventory_path) if File.exist?(ansible_inventory_path)
  90. File.open(ansible_inventory_path, 'w') do |f|
  91. HOSTS.each do |cfg|
  92. ssh_key = vagrant_root+"/.vagrant/machines/"+cfg[:hostname]+"/virtualbox/private_key"
  93. f.write "#{cfg[:hostname]} ansible_host=#{cfg[:ip]} ansible_ssh_private_key_file=#{ssh_key}\n"
  94. end
  95. groups.keys.each_with_index do |g, index|
  96. f.write "\n"
  97. f.write "[#{g}]\n"
  98. groups[g].each do |h|
  99. f.write "#{h}"
  100. network = NETWORK+"0/24"
  101. f.write " network_allowed="+network
  102. if g == "lbal_servers"
  103. HOSTS.each do |cfg|
  104. if cfg[:hostname] == h
  105. keepalived_priority = ""
  106. keepalived_state = ""
  107. unless cfg[:priority].to_s.strip.empty?
  108. keepalived_priority = " keepalived_priority="+cfg[:priority].to_s
  109. end
  110. unless cfg[:state].to_s.strip.empty?
  111. keepalived_state = " keepalived_state="+cfg[:state].to_s
  112. end
  113. f.write " ssl_name="+NCDOM+" keepalived_vip="+MAIN+keepalived_priority+keepalived_state
  114. end
  115. end
  116. end
  117. if g == "web_servers"
  118. HOSTS.each do |cfg|
  119. if cfg[:hostname] == h
  120. db_host = ""
  121. keepalived_priority = ""
  122. redis_daemon = ""
  123. redis_port = ""
  124. keepalived_vip = ""
  125. redis_host = ""
  126. unless cfg[:ipdb].to_s.strip.empty?
  127. db_host = " db_host="+cfg[:ipdb].to_s
  128. end
  129. unless cfg[:priority].to_s.strip.empty?
  130. keepalived_priority = " keepalived_priority="+cfg[:priority].to_s
  131. end
  132. unless cfg[:redisd].to_s.strip.empty?
  133. redis_daemon = " redis_daemon="+cfg[:redisd].to_s
  134. end
  135. unless cfg[:redisp].to_s.strip.empty?
  136. redis_port = " redis_port="+cfg[:redisp].to_s
  137. end
  138. unless cfg[:redisv].to_s.strip.empty?
  139. keepalived_vip = " keepalived_vip="+cfg[:redisv].to_s
  140. redis_host = " redis_host="+cfg[:redisv].to_s
  141. end
  142. if groups.count("web_servers") > 2
  143. f.write " nc_global_name="+NCDOM+db_host+redis_daemon+redis_port+redis_host+keepalived_vip+keepalived_priority
  144. else
  145. f.write " nc_global_name="+NCDOM+db_host+redis_daemon+redis_port
  146. end
  147. end
  148. end
  149. end
  150. if g == "db_lbal_servers"
  151. HOSTS.each do |cfg|
  152. if cfg[:hostname] == h
  153. keepalived_priority = ""
  154. keepalived_state = ""
  155. keepalived_vip = ""
  156. unless cfg[:priority].to_s.strip.empty?
  157. keepalived_priority = " keepalived_priority="+cfg[:priority].to_s
  158. end
  159. unless cfg[:state].to_s.strip.empty?
  160. keepalived_state = " keepalived_state="+cfg[:state].to_s
  161. end
  162. unless cfg[:vip].to_s.strip.empty?
  163. keepalived_vip = " keepalived_vip="+cfg[:vip].to_s
  164. end
  165. f.write keepalived_vip+keepalived_priority+keepalived_state
  166. end
  167. end
  168. end
  169. if g == "test_servers"
  170. HOSTS.each do |cfg|
  171. if cfg[:hostname] == h
  172. keepalived_priority = ""
  173. redis_daemon = ""
  174. redis_port = ""
  175. keepalived_vip = ""
  176. redis_host = ""
  177. unless cfg[:priority].to_s.strip.empty?
  178. keepalived_priority = " keepalived_priority="+cfg[:priority].to_s
  179. end
  180. unless cfg[:redisd].to_s.strip.empty?
  181. redis_daemon = " redis_daemon="+cfg[:redisd].to_s
  182. end
  183. unless cfg[:redisp].to_s.strip.empty?
  184. redis_port = " redis_port="+cfg[:redisp].to_s
  185. end
  186. unless cfg[:redisv].to_s.strip.empty?
  187. keepalived_vip = " keepalived_vip="+cfg[:redisv].to_s
  188. redis_host = " redis_host="+cfg[:redisv].to_s
  189. end
  190. f.write redis_daemon+redis_port+redis_host+keepalived_vip+keepalived_priority
  191. end
  192. end
  193. end
  194. f.write "\n"
  195. end
  196. end
  197. end
  198. # VM DEFINITIONS
  199. HOSTS.each_with_index do |server, index|
  200. config.vm.define server[:hostname] do |conf|
  201. conf.vm.box = server[:box]
  202. conf.vm.hostname = server[:hostname]
  203. conf.vm.boot_timeout = 360
  204. # Set system options
  205. cpu = server[:cpu] ? server[:cpu] : 1;
  206. memory = server[:ram] ? server[:ram] : 512;
  207. if server[:group] == "db_servers"
  208. conf.disksize.size = '100GB'
  209. end
  210. if server[:group] == "web_servers"
  211. conf.disksize.size = '1300GB'
  212. end
  213. #if server[:group] == "ceph_servers"
  214. # conf.disksize.size = '600GB'
  215. #end
  216. name = server[:hostname] ? server[:hostname] : "linux";
  217. conf.vm.synced_folder ".", "/vagrant", disabled: true
  218. conf.vm.provider "virtualbox" do |vbox|
  219. vbox.cpus = cpu.to_s
  220. vbox.memory = memory.to_s
  221. vbox.name = name
  222. if server[:box] == "rockylinux/8"
  223. vbox.customize ["modifyvm", :id, "--firmware", "efi"]
  224. end
  225. #if server[:group] != "web_servers"
  226. if Vagrant.has_plugin?("vagrant-vbguest")
  227. conf.vbguest.auto_update = false
  228. end
  229. #end
  230. end
  231. if !server[:disk_extra].nil? && !server[:disk_name].nil?
  232. disk = server[:disk_extra] ? server[:disk_extra] : "10GB";
  233. dname = server[:disk_name] ? server[:disk_name] : "extra_storage"
  234. conf.vm.disk :disk, size: disk.to_s, name: dname.to_s
  235. end
  236. if !server[:synced_folder].nil?
  237. host_folder = server[:synced_folder]
  238. #if server[:group] == "web_servers"
  239. # guest_folder = "/external"
  240. # conf.vm.network "forwarded_port", guest: 636, host: 636
  241. # conf.vm.synced_folder host_folder.to_s, guest_folder.to_s, mount_options: ["uid=48", "gid=48"]
  242. #end
  243. if server[:group] == "db_servers"
  244. guest_folder = "/external"
  245. conf.vm.synced_folder host_folder.to_s, guest_folder.to_s, mount_options: ["uid=993", "gid=989"]
  246. end
  247. end
  248. # Set network options
  249. netmask = server[:netmask] || NETMASK
  250. conf.vm.network :private_network, ip: server[:ip], netmask: netmask
  251. # Set port forwarding if defined
  252. if !server[:port_guest].nil? && !server[:port_host].nil?
  253. conf.vm.network "forwarded_port", guest: server[:port_guest], host: server[:port_host]
  254. end
  255. # Set synced folders if defined
  256. if !server[:folder_guest].nil? && !server[:folder_host].nil?
  257. conf.vm.synced_folder server[:folder_host], server[:folder_guest]
  258. end
  259. # Set common provision
  260. conf.vm.provision "shell" do |s|
  261. s.path = "provisioning/bash/common.sh"
  262. s.args = [server[:box]]
  263. end
  264. # Provision nodes with Ansible.
  265. # The index used here in order to execute the provision just after all
  266. # the servers are up and running.
  267. if index == HOSTS.size - 1
  268. if ansible_playbook != ""
  269. conf.vm.provision :ansible do |ansible|
  270. ansible.limit = "all"
  271. ansible.compatibility_mode = "2.0"
  272. ansible.inventory_path = ansible_inventory_path
  273. ansible.playbook = ansible_playbook
  274. ansible.become = true
  275. #ansible.verbose = "vvvv"
  276. end
  277. end
  278. end
  279. end
  280. end
  281. # VM PROVISIONING
  282. # #Prometheus
  283. # config.vm.define "prometheus" do |prometheus|
  284. # prometheus.vm.box = 'centos/7'
  285. # prometheus.vm.hostname = "prometheus"
  286. # prometheus.vm.network :private_network, ip: "192.168.56.41"
  287. # prometheus.vm.provision "shell", path: "provisioning/install/Centos_7.sh"
  288. #
  289. # #Provision prometheus-grafana with Ansible
  290. # prometheus.vm.provision "ansible" do |ansible|
  291. # ansible.compatibility_mode = "2.0"
  292. # ansible.playbook="provisioning/ansible/prometheus.yml"
  293. # ansible.become = true
  294. # ansible.extra_vars = {
  295. # ansible_python_interpreter: "/usr/bin/python2",
  296. # }
  297. # end
  298. # end
  299. #
  300. # #Node Exporter
  301. # config.vm.define "node" do |node|
  302. # node.vm.box = 'centos/7'
  303. # node.vm.hostname = "nodexporter"
  304. # node.vm.network :private_network, ip: "192.168.56.42"
  305. # node.vm.provision "shell", path: "provisioning/install/Centos_7.sh"
  306. #
  307. # #Provision prometheus-grafana with Ansible
  308. # node.vm.provision "ansible" do |ansible|
  309. # ansible.compatibility_mode = "2.0"
  310. # ansible.playbook="provisioning/ansible/node_exporter.yml"
  311. # ansible.become = true
  312. # ansible.extra_vars = {
  313. # ansible_python_interpreter: "/usr/bin/python2",
  314. # }
  315. # end
  316. # end
  317. #
  318. # #Grafana
  319. # config.vm.define "grafana" do |grafana|
  320. # grafana.vm.box = 'centos/7'
  321. # grafana.vm.hostname = "grafana"
  322. # grafana.vm.network :private_network, ip: "192.168.56.43"
  323. # grafana.vm.provision "shell", path: "provisioning/install/Centos_7.sh"
  324. #
  325. # #Provision prometheus-grafana with Ansible
  326. # grafana.vm.provision "ansible" do |ansible|
  327. # ansible.compatibility_mode = "2.0"
  328. # ansible.playbook="provisioning/ansible/grafana.yml"
  329. # ansible.become = true
  330. # ansible.extra_vars = {
  331. # ansible_python_interpreter: "/usr/bin/python2",
  332. # }
  333. # end
  334. # end
  335. #end
  336. end