-
Notifications
You must be signed in to change notification settings - Fork 5
/
Vagrantfile
92 lines (73 loc) · 2.8 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
require 'ipaddr'
#require 'yaml'
ENV["LC_ALL"] = 'en_US.utf8'
pgver = 11
start_ip = '10.20.30.50'
etcd_nodes = 'e1', 'e2', 'e3' # you must have 3+ etcd nodes
patroni_nodes = 'p1', 'p2' # you must have 2+ patroni nodes
Vagrant.configure(2) do |config|
vip_ip = IPAddr.new(start_ip)
next_ip = IPAddr.new(start_ip).succ
nodes_ips = {}
( patroni_nodes + etcd_nodes ).each do |node|
nodes_ips[node] = next_ip.to_s
next_ip = next_ip.succ
end
# don't mind about insecure ssh key
config.ssh.insert_key = false
# https://vagrantcloud.com/search.
config.vm.box = 'centos/7'
# hardware and host settings
config.vm.provider 'libvirt' do |lv|
lv.cpus = 1
lv.memory = 512
lv.watchdog model: 'i6300esb'
lv.default_prefix = 'patroni_'
lv.qemu_use_session = false
end
# disable default share
config.vm.synced_folder ".", "/vagrant", disabled: true
## allow root@vm to ssh to ssh_login@network_1
#config.vm.synced_folder 'ssh', '/root/.ssh', type: 'rsync',
# owner: 'root', group: 'root',
# rsync__args: [ "--verbose", "--archive", "--delete", "--copy-links", "--no-perms" ]
# system setup for etcd nodes
(etcd_nodes).each do |node|
config.vm.define node do |conf|
conf.vm.network 'private_network', ip: nodes_ips[node]
conf.vm.provision 'etcd-setup', type: 'shell', path: 'provision/etcd.bash',
args: [ node ] + etcd_nodes.map {|n| "#{n}=#{nodes_ips[n]}"},
preserve_order: true
end
end
# system setup for patroni nodes
(patroni_nodes).each do |node|
config.vm.define node do |conf|
args = [ '-n', node ];
(etcd_nodes).each do |e|
args.push("-e", "#{e}=#{nodes_ips[e]}")
end
conf.vm.network 'private_network', ip: nodes_ips[node]
conf.vm.provision 'vipmanager-setup', type: 'shell',
path: 'provision/vipmanager.bash',
args: args + [ '-i', vip_ip.to_s],
run: 'never'
(patroni_nodes).each do |p|
args.push("-p", "#{p}=#{nodes_ips[p]}")
end
conf.vm.provision 'patroni-setup', type: 'shell',
path: 'provision/patroni.bash',
args: args + [ '-v', pgver ] ,
preserve_order: true
end
end
# Start Patroni and/or vipmanager on all nodes
(patroni_nodes).each do |node|
config.vm.define node do |conf|
conf.vm.provision 'patroni-start', type: 'shell',
inline: 'systemctl start patroni@demo', run: 'never'
conf.vm.provision 'vipmanager-start', type: 'shell',
inline: 'systemctl restart vip-manager.service', run: 'never'
end
end
end