blob: c8351e75bf7165205d3c0c82f92774d6b8db2696 [file] [log] [blame]
Dennis Dmitriev77d886c2017-05-24 13:13:26 +03001{% from 'physical_mcp11_dvr/underlay.yaml' import HOSTNAME_CFG01 with context %}
2{% from 'physical_mcp11_dvr/underlay.yaml' import REPOSITORY_SUITE with context %}
3
4{% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/mcp-baremetal-lab') %}
Valentyn Yakovlev08acf9f2017-06-07 14:02:36 +03005{% set SALT_MODELS_BRANCH = os_env('SALT_MODELS_BRANCH','master') %}
Dennis Dmitriev77d886c2017-05-24 13:13:26 +03006{% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %}
7
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +03008# Reference to a patch that should be applied to the model if required, for example: export SALT_MODELS_REF_CHANGE=refs/changes/19/7219/12
9{% set SALT_MODELS_REF_CHANGE = os_env('SALT_MODELS_REF_CHANGE', '') %}
10
Dennis Dmitriev77d886c2017-05-24 13:13:26 +030011# Address pools for reclass cluster model are taken in the following order:
12# 1. environment variables,
13# 2. config.underlay.address_pools based on fuel-devops address pools
14# (see generated '.ini' file after underlay is created),
15# 3. defaults
16{% set address_pools = config.underlay.address_pools %}
17
18# Install salt to the config node
19
Dennis Dmitriev77d886c2017-05-24 13:13:26 +030020- description: Installing salt master on cfg01
21 cmd: eatmydata apt-get install -y reclass git salt-master
22 node_name: {{ HOSTNAME_CFG01 }}
23 retry: {count: 1, delay: 1}
24 skip_fail: false
25
Dennis Dmitriev77d886c2017-05-24 13:13:26 +030026- description: Configure salt-master on cfg01
27 cmd: |
28 cat << 'EOF' >> /etc/salt/master.d/master.conf
29 file_roots:
30 base:
31 - /usr/share/salt-formulas/env
32 pillar_opts: False
33 open_mode: True
34 reclass: &reclass
35 storage_type: yaml_fs
36 inventory_base_uri: /srv/salt/reclass
37 ext_pillar:
38 - reclass: *reclass
39 master_tops:
40 reclass: *reclass
41 EOF
42 node_name: {{ HOSTNAME_CFG01 }}
43 retry: {count: 1, delay: 1}
44 skip_fail: false
45
46- description: Configure GIT settings and certificates
47 cmd: touch /root/.git_trusted_certs.pem;
Matthew Mosesohnd0632b82017-05-30 17:51:30 +030048 for server in github.com; do
Dennis Dmitriev77d886c2017-05-24 13:13:26 +030049 openssl s_client -showcerts -connect $server:443 </dev/null
50 | openssl x509 -outform PEM
51 >> /root/.git_trusted_certs.pem;
52 done;
53 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
54 HOME=/root git config --global user.email "tcp-qa@example.com";
55 HOME=/root git config --global user.name "TCP QA";
56 node_name: {{ HOSTNAME_CFG01 }}
57 retry: {count: 1, delay: 1}
58 skip_fail: false
59
60
61- description: Clone reclass models with submodules
62 cmd: |
63 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Valentyn Yakovlev08acf9f2017-06-07 14:02:36 +030064 git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
65 pushd /srv/salt/reclass && git checkout {{ SALT_MODELS_COMMIT }} && popd;
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030066 {%- if SALT_MODELS_REF_CHANGE != '' %}
67 pushd /srv/salt/reclass && git fetch {{ SALT_MODELS_REPOSITORY }} {{ SALT_MODELS_REF_CHANGE }} && git checkout FETCH_HEAD && popd;
68 {%- endif %}
Dennis Dmitriev77d886c2017-05-24 13:13:26 +030069 mkdir -p /srv/salt/reclass/classes/service;
70
71 # Replace firstly to an intermediate value to avoid intersection between
72 # already replaced and replacing networks.
73 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
74 # 192.168.10 -> 10.16.0 (generated network for admin)
75 # 10.16.0 -> <external network>
76 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
77
78 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
79
80 # Disable checkouting the model from remote repository
81 cat << 'EOF' >> /srv/salt/reclass/nodes/control/{{ HOSTNAME_CFG01 }}.yml
82 # local storage
83 reclass:
84 storage:
85 data_source:
86 engine: local
87 EOF
88
89 # Show the changes to the console
90 cd /srv/salt/reclass/; git diff
91 node_name: {{ HOSTNAME_CFG01 }}
92 retry: {count: 1, delay: 1}
93 skip_fail: false
94
95- description: Configure reclass
96 cmd: |
97 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
obutenko89aedf82017-08-04 12:50:37 +030098 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial stable salt};
99 FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg};
Dennis Dmitriev77d886c2017-05-24 13:13:26 +0300100 which wget > /dev/null || (apt-get update; apt-get install -y wget);
101 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
102 wget -O - "${FORMULA_GPG}" | apt-key add -;
103 apt-get clean; apt-get update;
104 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich644446f2017-06-08 13:43:36 +0300105 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch");
Dennis Dmitriev77d886c2017-05-24 13:13:26 +0300106 echo -e "\nInstalling all required salt formulas\n";
107 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
108 for formula_service in "${formula_services[@]}"; do
109 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
110 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
111 done;
112 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
113 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
114 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
115
116 cat << 'EOF' >> /etc/reclass/reclass-config.yml
117 storage_type: yaml_fs
118 pretty_print: True
119 output: yaml
120 inventory_base_uri: /srv/salt/reclass
121 EOF
122 node_name: {{ HOSTNAME_CFG01 }}
123 retry: {count: 1, delay: 1}
124 skip_fail: false
125
126- description: Restart salt-master service
127 cmd: |
Dennis Dmitriev266ec072017-05-25 13:39:17 +0300128 systemctl restart salt-master; sleep 60
Dennis Dmitriev77d886c2017-05-24 13:13:26 +0300129 node_name: {{ HOSTNAME_CFG01 }}
130 retry: {count: 1, delay: 5}
131 skip_fail: false
132
133{% for ssh in config.underlay.ssh %}
134- description: Configure salt-minion on {{ ssh['node_name'] }}
135 cmd: |
136 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
137 cat << "EOF" >> /etc/salt/minion.d/minion.conf
138 id: {{ ssh['node_name'] }}
139 master: {{ config.salt.salt_master_host }}
140 EOF
141 eatmydata apt-get install -y salt-minion;
142 echo "Check for system info and metadata availability ...";
143 salt-call --no-color grains.items;
144 salt-call --no-color pillar.items;
145 node_name: {{ ssh['node_name'] }}
146 retry: {count: 1, delay: 1}
147 skip_fail: false
148{% endfor %}
149
150
151- description: Accept salt keys from all the nodes
152 cmd: salt-key -A -y
153 node_name: {{ HOSTNAME_CFG01 }}
154 retry: {count: 1, delay: 5}
155 skip_fail: true
156
157
158- description: Configure salt adoptors on cfg01
159 cmd: |
160 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
161 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
162 node_name: {{ HOSTNAME_CFG01 }}
163 retry: {count: 1, delay: 1}
164 skip_fail: false
165
166
167# Prepare salt services and nodes settings
168- description: Run 'linux' formula on cfg01
169 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
170 -C 'I@salt:master' state.sls linux;
171 node_name: {{ HOSTNAME_CFG01 }}
172 retry: {count: 3, delay: 5}
173 skip_fail: false
174
175
176- description: Run 'openssh' formula on cfg01
177 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
178 -C 'I@salt:master' state.sls openssh;
179 salt --hard-crash --state-output=mixed --state-verbose=False
180 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
181 yes/' /etc/ssh/sshd_config && service ssh restart";
182 node_name: {{ HOSTNAME_CFG01 }}
183 retry: {count: 3, delay: 5}
184 skip_fail: false
185
186
187- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
188 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
189 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
190 node_name: {{ HOSTNAME_CFG01 }}
191 retry: {count: 1, delay: 1}
192 skip_fail: false
193
194- description: Run 'salt.master' formula on cfg01
195 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
196 -C 'I@salt:master' state.sls salt.master.service;
197 node_name: {{ HOSTNAME_CFG01 }}
198 retry: {count: 2, delay: 5}
199 skip_fail: false
200
201- description: Run 'salt' formula on cfg01 with workaround proposed in PROD-10894
202 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
203 -C 'I@salt:master' state.sls salt;
204 salt --hard-crash --state-output=mixed --state-verbose=False
205 -C 'I@salt:master' saltutil.sync_all
206 node_name: {{ HOSTNAME_CFG01 }}
207 retry: {count: 5, delay: 5}
208 skip_fail: false
209
210- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
211 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
212 -C 'I@salt:master' state.sls reclass
213 node_name: {{ HOSTNAME_CFG01 }}
214 retry: {count: 1, delay: 5}
215 skip_fail: false
216
217
218
Dennis Dmitrieve17bcaf2017-05-25 00:26:57 +0300219- description: Refresh pillars for present baremetal nodes
220 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
Dennis Dmitriev77d886c2017-05-24 13:13:26 +0300221 node_name: {{ HOSTNAME_CFG01 }}
222 retry: {count: 1, delay: 5}
223 skip_fail: false
224
Dennis Dmitrieve17bcaf2017-05-25 00:26:57 +0300225- description: Sync all salt resources for present baremetal nodes
226 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
227 node_name: {{ HOSTNAME_CFG01 }}
228 retry: {count: 1, delay: 5}
229 skip_fail: false
230
231- description: Configure linux for present baremetal nodes
232 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
233 cfg01*' state.sls linux
234 node_name: {{ HOSTNAME_CFG01 }}
235 retry: {count: 3, delay: 5}
236 skip_fail: false
237
238- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-9576 to get bond0-connectivity *without* rebooting nodes'
239 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' cmd.run
240 "cat /etc/network/interfaces | grep bond-slaves | awk '{print \$2}' | xargs -I {} ifenslave bond0 {}"
Dennis Dmitriev77d886c2017-05-24 13:13:26 +0300241 node_name: {{ HOSTNAME_CFG01 }}
242 retry: {count: 1, delay: 5}
243 skip_fail: false
244
245- description: ovs-dvr-vlan model specific Execute 'libvirt' states to create necessary libvirt networks
246 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'kvm*' state.sls libvirt
247 node_name: {{ HOSTNAME_CFG01 }}
248 retry: {count: 1, delay: 10}
249 skip_fail: false
250
251- description: Create VMs for control plane
252 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'kvm*' state.sls salt.control
253 node_name: {{ HOSTNAME_CFG01 }}
254 retry: {count: 3, delay: 10}
255 skip_fail: false
256
257
258
259- description: Refresh pillars on all minions
260 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
261 node_name: {{ HOSTNAME_CFG01 }}
262 retry: {count: 1, delay: 5}
263 skip_fail: false
264
265- description: Sync all salt resources
266 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
267 node_name: {{ HOSTNAME_CFG01 }}
268 retry: {count: 1, delay: 5}
269 skip_fail: false
270
271- description: Show reclass-salt --top for generated nodes
272 cmd: reclass-salt --top -u /srv/salt/reclass/nodes/_generated/
273 node_name: {{ HOSTNAME_CFG01 }}
274 retry: {count: 1, delay: 5}
275 skip_fail: false
276
277- description: Execute salt.minion.cert
278 cmd: salt-call --no-color state.sls salt.minion.cert -l info;
279 node_name: {{ HOSTNAME_CFG01 }}
280 retry: {count: 1, delay: 5}
281 skip_fail: false
282
283
284# Bootstrap all nodes
285
286- description: Configure linux on other nodes
287 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
288 cfg01*' state.sls linux
289 node_name: {{ HOSTNAME_CFG01 }}
290 retry: {count: 3, delay: 5}
291 skip_fail: false
292
293- description: Configure openssh on all nodes
294 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
295 cfg01*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
296 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
297 yes/' /etc/ssh/sshd_config && service ssh restart"
298 node_name: {{ HOSTNAME_CFG01 }}
299 retry: {count: 1, delay: 5}
300 skip_fail: false
301
302- description: Configure salt.minion on other nodes
303 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
304 cfg01*' state.sls salt.minion
305 node_name: {{ HOSTNAME_CFG01 }}
306 retry: {count: 3, delay: 5}
307 skip_fail: false
308
309- description: Check salt minion versions on slaves
310 cmd: salt '*' test.version
311 node_name: {{ HOSTNAME_CFG01 }}
312 retry: {count: 1, delay: 5}
313 skip_fail: false
314
315- description: Check salt top states on nodes
316 cmd: salt '*' state.show_top
317 node_name: {{ HOSTNAME_CFG01 }}
318 retry: {count: 1, delay: 5}
319 skip_fail: false
320
321- description: Configure ntp and rsyslog on nodes
322 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog
323 node_name: {{ HOSTNAME_CFG01 }}
324 retry: {count: 1, delay: 10}
325 skip_fail: false
326
327
328#- description: Hack gtw node
329# cmd: salt 'gtw*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4";
330# node_name: {{ HOSTNAME_CFG01 }}
331# retry: {count: 1, delay: 10}
332# skip_fail: false
333
334#- description: Hack cmp01 node
335# cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
336# node_name: {{ HOSTNAME_CFG01 }}
337# retry: {count: 1, delay: 10}
338# skip_fail: false
339
340#- description: Hack cmp02 node
341# cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
342# node_name: {{ HOSTNAME_CFG01 }}
343# retry: {count: 1, delay: 10}
344# skip_fail: false