-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
executable file
·322 lines (262 loc) · 11.1 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'yaml'
raise Vagrant::Errors::VagrantError.new,
"'settings.yml' file not found.\n\n" \
"Please define your 'settings.yml'. " \
"See 'settings.sample.yml' for an example." unless File.exist?("settings.yml")
settings = YAML.load_file('settings.yml')
num_volumes = settings.has_key?('vm_num_volumes') ?
settings['vm_num_volumes'] : 2
volume_size = settings.has_key?('vm_volume_size') ?
settings['vm_volume_size'] : '8G'
num_nodes = settings.has_key?('num_nodes') ?
settings['num_nodes'] : 3
raise Vagrant::Errors::VagrantError.new,
"Invalid 'num_nodes' (#{num_nodes}).\n\n" \
"Supported values: 2 or 3" unless ([2,3]).include?(num_nodes)
Vagrant.configure("2") do |config|
config.ssh.insert_key = false
config.vm.box = "suse/SLE12SP3-x86_64"
config.vm.provider "libvirt" do |lv|
if settings.has_key?('libvirt_host') then
lv.host = settings['libvirt_host']
end
if settings.has_key?('libvirt_user') then
lv.username = settings['libvirt_user']
end
if settings.has_key?('libvirt_use_ssl') then
lv.connect_via_ssh = true
end
lv.memory = settings.has_key?('vm_memory') ? settings['vm_memory'] : 4096
lv.cpus = settings.has_key?('vm_cpus') ? settings['vm_cpus'] : 2
if settings.has_key?('vm_storage_pool') then
lv.storage_pool_name = settings['vm_storage_pool']
end
end
config.vm.define :node1 do |node|
node.vm.hostname = "node1.oa.local"
node.vm.network :private_network, ip: "192.168.100.201"
node.vm.network :private_network, ip: "192.168.170.201"
node.vm.provision "file", source: "keys/id_rsa",
destination:".ssh/id_rsa"
node.vm.provision "file", source: "keys/id_rsa.pub",
destination:".ssh/id_rsa.pub"
node.vm.synced_folder ".", "/vagrant", disabled: true
node.vm.provider "libvirt" do |lv|
(1..num_volumes).each do |d|
lv.storage :file, size: volume_size, type: 'qcow2'
end
end
node.vm.provision "shell", inline: <<-SHELL
echo "192.168.100.200 salt salt.oa.local" >> /etc/hosts
echo "192.168.100.201 node1 node1.oa.local" >> /etc/hosts
echo "192.168.100.202 node2 node2.oa.local" >> /etc/hosts
echo "192.168.100.203 node3 node3.oa.local" >> /etc/hosts
cat /home/vagrant/.ssh/id_rsa.pub >> /home/vagrant/.ssh/authorized_keys
chmod 600 /home/vagrant/.ssh/id_rsa
cp /home/vagrant/.ssh/id_rsa* /root/.ssh/
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
hostname node1
SuSEfirewall2 off
zypper -n install ntp
zypper -n install salt-minion
systemctl enable salt-minion
systemctl start salt-minion
touch /tmp/ready
SHELL
end
if num_nodes > 1 then
config.vm.define :node2 do |node|
node.vm.hostname = "node2.oa.local"
node.vm.network :private_network, ip: "192.168.100.202"
node.vm.network :private_network, ip: "192.168.170.202"
node.vm.provision "file", source: "keys/id_rsa",
destination:".ssh/id_rsa"
node.vm.provision "file", source: "keys/id_rsa.pub",
destination:".ssh/id_rsa.pub"
node.vm.synced_folder ".", "/vagrant", disabled: true
node.vm.provider "libvirt" do |lv|
(1..num_volumes).each do |d|
lv.storage :file, size: volume_size, type: 'qcow2'
end
end
node.vm.provision "shell", inline: <<-SHELL
echo "192.168.100.200 salt salt.oa.local" >> /etc/hosts
echo "192.168.100.201 node1 node1.oa.local" >> /etc/hosts
echo "192.168.100.202 node2 node2.oa.local" >> /etc/hosts
echo "192.168.100.203 node3 node3.oa.local" >> /etc/hosts
cat /home/vagrant/.ssh/id_rsa.pub >> /home/vagrant/.ssh/authorized_keys
chmod 600 /home/vagrant/.ssh/id_rsa
cp /home/vagrant/.ssh/id_rsa* /root/.ssh/
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
hostname node2
ssh-keyscan -H salt >> ~/.ssh/known_hosts
ssh-keyscan -H node1 >> ~/.ssh/known_hosts
ssh-keyscan -H node3 >> ~/.ssh/known_hosts
SuSEfirewall2 off
zypper -n install ntp
zypper -n install salt-minion
systemctl enable salt-minion
systemctl start salt-minion
touch /tmp/ready
SHELL
end
end
if num_nodes > 2 then
config.vm.define :node3 do |node|
node.vm.hostname = "node3.oa.local"
node.vm.network :private_network, ip: "192.168.100.203"
node.vm.network :private_network, ip: "192.168.170.203"
node.vm.provision "file", source: "keys/id_rsa",
destination:".ssh/id_rsa"
node.vm.provision "file", source: "keys/id_rsa.pub",
destination:".ssh/id_rsa.pub"
node.vm.synced_folder ".", "/vagrant", disabled: true
node.vm.provider "libvirt" do |lv|
(1..num_volumes).each do |d|
lv.storage :file, size: volume_size, type: 'qcow2'
end
end
node.vm.provision "shell", inline: <<-SHELL
echo "192.168.100.200 salt salt.oa.local" >> /etc/hosts
echo "192.168.100.201 node1 node1.oa.local" >> /etc/hosts
echo "192.168.100.202 node2 node2.oa.local" >> /etc/hosts
echo "192.168.100.203 node3 node3.oa.local" >> /etc/hosts
cat /home/vagrant/.ssh/id_rsa.pub >> /home/vagrant/.ssh/authorized_keys
chmod 600 /home/vagrant/.ssh/id_rsa
cp /home/vagrant/.ssh/id_rsa* /root/.ssh/
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
ssh-keyscan -H salt >> ~/.ssh/known_hosts
ssh-keyscan -H node1 >> ~/.ssh/known_hosts
ssh-keyscan -H node2 >> ~/.ssh/known_hosts
hostname node3
SuSEfirewall2 off
zypper -n install ntp
zypper -n install salt-minion
systemctl enable salt-minion
systemctl start salt-minion
touch /tmp/ready
SHELL
end
end
config.vm.define :salt do |salt|
salt.vm.hostname = "salt.oa.local"
salt.vm.network :private_network, ip: "192.168.100.200"
salt.vm.provision "file", source: "keys/id_rsa",
destination:".ssh/id_rsa"
salt.vm.provision "file", source: "keys/id_rsa.pub",
destination:".ssh/id_rsa.pub"
salt.vm.provision "file", source: "bin",
destination:"."
roles = {
"mon" => "node*",
"igw" => ("node[12]*" if num_nodes > 1) || "node*",
"rgw" => ("node[13]*" if num_nodes > 2) || "node*",
"mds" => ("node[23]*" if num_nodes > 2) || "node*",
"ganesha" => ("node[23]*" if num_nodes > 2) || "node*",
"mgr" => ("node[12]*" if num_nodes > 1) || "node*"
}
salt.vm.provision "shell", inline: <<-SHELL
echo "192.168.100.200 salt salt.oa.local" >> /etc/hosts
echo "192.168.100.201 node1 node1.oa.local" >> /etc/hosts
echo "192.168.100.202 node2 node2.oa.local" >> /etc/hosts
echo "192.168.100.203 node3 node3.oa.local" >> /etc/hosts
cat /home/vagrant/.ssh/id_rsa.pub >> /home/vagrant/.ssh/authorized_keys
chmod 600 /home/vagrant/.ssh/id_rsa
cp /home/vagrant/.ssh/id_rsa* /root/.ssh/
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
hostname salt
zypper -n install ntp salt-minion salt-master git-core
systemctl enable ntpd
systemctl start ntpd
systemctl enable salt-master
systemctl start salt-master
sleep 5
systemctl enable salt-minion
systemctl start salt-minion
SuSEfirewall2 off
while : ; do
PROVISIONED_NODES=`ls -l /tmp/ready-* 2>/dev/null | wc -l`
echo "waiting for nodes (${PROVISIONED_NODES}/#{num_nodes})";
[[ "${PROVISIONED_NODES}" != "#{num_nodes}" ]] || break
sleep 10;
sudo scp -o StrictHostKeyChecking=no node1:/tmp/ready /tmp/ready-node1 2>/dev/null;
sudo scp -o StrictHostKeyChecking=no node2:/tmp/ready /tmp/ready-node2 2>/dev/null;
sudo scp -o StrictHostKeyChecking=no node3:/tmp/ready /tmp/ready-node3 2>/dev/null;
done
zypper ref
zypper in -y deepsea
cat > /srv/salt/ceph/updates/default_my.sls <<EOF
dummy command:
test.nop
EOF
cp /srv/salt/ceph/updates/default_my.sls /srv/salt/ceph/updates/restart
sed -i 's/default/default_my/g' /srv/salt/ceph/updates/init.sls
sed -i 's/default/default_my/g' /srv/salt/ceph/updates/restart/init.sls
cp /srv/salt/ceph/updates/default_my.sls /srv/salt/ceph/time
sed -i 's/default/default_my/g' /srv/salt/ceph/time/init.sls
echo "deepsea_minions: '*'" > /srv/pillar/ceph/deepsea_minions.sls
sed -i 's/#worker_threads: 5/worker_threads: 10/g' /etc/salt/master
chown -R salt:salt /srv/pillar
systemctl restart salt-master
sleep 10
ssh -o StrictHostKeyChecking=no node1 "systemctl restart salt-minion.service"
ssh -o StrictHostKeyChecking=no node2 "systemctl restart salt-minion.service"
ssh -o StrictHostKeyChecking=no node3 "systemctl restart salt-minion.service"
ssh -o StrictHostKeyChecking=no salt "systemctl restart salt-minion.service"
sleep 5
echo -e "Accept the salt-minion keys"
salt-key -Ay
echo "[DeepSea] Stage 0 - prep"
salt-run state.orch ceph.stage.prep
sleep 10
echo "[DeepSea] Installing and Activating Salt-API"
salt-call state.apply ceph.salt-api
sleep 10
echo "[DeepSea] Stage 1 - discovery"
salt-run state.orch ceph.stage.discovery
cat > /srv/pillar/ceph/proposals/policy.cfg <<EOF
# Cluster assignment
cluster-ceph/cluster/*.sls
# Hardware Profile
profile-default/cluster/*.sls
profile-default/stack/default/ceph/minions/*yml
# Common configuration
config/stack/default/global.yml
config/stack/default/ceph/cluster.yml
# Role assignment
role-master/cluster/salt*.sls
role-admin/cluster/salt*.sls
role-mon/cluster/#{roles['mon']}.sls
role-igw/cluster/#{roles['igw']}.sls
role-rgw/cluster/#{roles['rgw']}.sls
role-mds/cluster/#{roles['mds']}.sls
role-mon/stack/default/ceph/minions/#{roles['mon']}.yml
role-ganesha/cluster/#{roles['ganesha']}.sls
role-mgr/cluster/#{roles['mgr']}.sls
role-openattic/cluster/salt*.sls
EOF
chown salt:salt /srv/pillar/ceph/proposals/policy.cfg
cat > /srv/pillar/ceph/rgw.sls <<EOF
rgw_configurations:
rgw:
users:
- { uid: "admin", name: "Admin", email: "[email protected]", system: True }
EOF
chown salt:salt /srv/pillar/ceph/rgw.sls
sleep 2
echo "[DeepSea] Stage 2 - configure"
salt-run state.orch ceph.stage.configure
sed -i 's/time_init:.*ntp/time_init: default_my/g' /srv/pillar/ceph/stack/default/global.yml
sleep 5
echo "[DeepSea] Stage 3 - deploy"
DEV_ENV='true' salt-run state.orch ceph.stage.deploy
sleep 5
echo "[DeepSea] Stage 4 - services"
DEV_ENV='true' salt-run state.orch ceph.stage.4
chmod 644 /etc/ceph/ceph.client.admin.keyring
touch /tmp/ready
SHELL
end
end