-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
109 lines (88 loc) · 2.75 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Require YAML module
require 'yaml'
# Vagrant API version
VAGRANTFILE_API_VERSION = "2"
# Read cluster settings
cluster_config = YAML.load_file('etc/cluster_config.yml')
servers = cluster_config["servers"]
providers = cluster_config["providers"]
## Check for missing plugins
#required_plugins = %w(vagrant-hostmanager vagrant-vbguest)
#plugin_installed = false
#required_plugins.each do |plugin|
# unless Vagrant.has_plugin?(plugin)
# system "vagrant plugin install #{plugin}"
# plugin_installed = true
# end
#end
## If new plugins installed, restart Vagrant process
#if plugin_installed === true
# exec "vagrant #{ARGV.join' '}"
#end
# Create boxes
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if Vagrant.has_plugin?("vagrant-hostmanager")
config.hostmanager.enabled = true
config.hostmanager.manage_host = false
config.hostmanager.manage_guest = true
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true
end
if Vagrant.has_plugin?("vagrant-vbguest")
config.vbguest.auto_update = false
end
$ansible_groups = {}
# Collect server groups
servers.each do |server|
role = server["role"]
host = server["name"]
if $ansible_groups.has_key?(role)
$ansible_groups[role] << host
else
$ansible_groups[role] = [host]
end
end
$host_vars = {}
servers.each do |server|
host = server["name"]
$host_vars[host] = {}
server.each do |key, value|
$host_vars[host]["instance_" + key] = value
end
end
$count = 0
servers.each do |server|
config.vm.define server["name"] do |srv|
srv.vm.box = server["box"]
srv.vm.hostname = server["name"]
srv.vm.network "private_network", ip: server["ip"] #, auto_config: false
if providers["virtualbox"]["enable"]
srv.vm.provider :virtualbox do |vb|
vb.name = server["name"]
vb.cpus = server["cpu"]
vb.memory = server["ram"]
end
end
## Setting up static ip bug
#srv.vm.provision "shell", inline: "sudo nmcli connection reload"
#srv.vm.provision "shell", inline: "sudo systemctl restart network.service"
if $count == servers.length - 1
## Ansible configuration
config.vm.provision :ansible do |ansible|
#ansible.verbose = "vvvv"
#ansible.playbook = server["role"]+".yml"
#ansible.version = "latest"
ansible.limit = "all"
ansible.compatibility_mode = "2.0"
ansible.playbook = 'ansible/playbook.yaml'
ansible.host_key_checking = false
ansible.groups = $ansible_groups
ansible.host_vars = $host_vars
end
end
$count = $count + 1
end
end
end