-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
108 lines (95 loc) · 2.73 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
nodes = {
'node1' => {
'ip' => '192.168.70.101',
'groups' => ['mysql_nodes', 'cluster_nodes'],
'host_vars' => {
"mysql_server_id" => "1",
"mysql_replication_role" => 'master',
},
},
'node2' => {
'ip' => '192.168.70.102',
'groups' => ['mysql_nodes', 'cluster_nodes'],
'host_vars' => {
"mysql_server_id" => "2",
"mysql_replication_role" => 'slave'
},
},
'node3' => {
'ip' => '192.168.70.103',
'groups' => ['cluster_nodes'],
},
'node4' => {
'ip' => '192.168.70.104',
'groups' => [],
}
}
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = 'minimal/centos6'
config.vm.boot_timeout = 600
config.hostmanager.enabled = false
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--memory", 1024]
end
# Create all nodes according to their spec
nodes.each_pair { |node, node_params|
config.vm.define node do |node_config|
node_config.vm.hostname = node
node_config.vm.network :private_network, ip: node_params['ip']
end
}
# Reset the hosts files for the cluster nodes.
config.vm.provision :ansible do |ansible|
ansible.verbose = 'vv'
ansible.sudo = true
ansible.groups = Hash.new
ansible.host_vars = Hash.new
nodes.each_pair { |node, node_config|
node_config['groups'].each { |group|
if ansible.groups.include?(group)
ansible.groups[group].push(node)
else
ansible.groups[group] = [node]
end
}
ansible.host_vars[node] = node_config['host_vars']
}
ansible.extra_vars = {
ansible_ssh_user: 'vagrant',
}
# Disable default limit (required with Vagrant 1.5+)
ansible.limit = 'all'
ansible.playbook = "provisioning/reset-hosts-file.yml"
ansible.host_key_checking = false
end
# Set up the host files
config.vm.provision :hostmanager
# Provision the software
config.vm.provision :ansible do |ansible|
ansible.verbose = 'vv'
ansible.sudo = true
ansible.groups = Hash.new
ansible.host_vars = Hash.new
nodes.each_pair { |node, node_config|
node_config['groups'].each { |group|
if ansible.groups.include?(group)
ansible.groups[group].push(node)
else
ansible.groups[group] = [node]
end
}
ansible.host_vars[node] = node_config['host_vars']
}
ansible.extra_vars = {
ansible_ssh_user: 'vagrant',
}
# Disable default limit (required with Vagrant 1.5+)
ansible.limit = 'all'
ansible.playbook = "provisioning/site.yml"
ansible.host_key_checking = false
end
end