blob: 0bda6d05a12b6e5c9c5ecf692f6add1c9396ffec [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
20#- description: (moved to cloud-init config) Configure repository on the cfg01 node
21# cmd:
22# echo "172.18.248.114 jenkins.mcp.mirantis.net gerrit.mcp.mirantis.net" >> /etc/hosts;
23# echo "185.135.196.10 apt-mk.mirantis.com" >> /etc/hosts;
24# echo "nameserver 172.18.208.44 >> /etc/resolv.conf;
25# echo "nameserver 8.8.8.8 >> /etc/resolv.conf;
26# which wget >/dev/null || (apt-get update; apt-get install -y wget);
27# echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial nightly salt extra" > /etc/apt/sources.list.d/mcp_salt.list;
28# wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -;
29# echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list;
30# wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -;
31# node_name: {{ HOSTNAME_CFG01 }}
32# retry: {count: 1, delay: 1}
33# skip_fail: false
34
35#- description: Update packages on cfg01
36# cmd: apt-get clean; eatmydata apt-get update
37# node_name: {{ HOSTNAME_CFG01 }}
38# retry: {count: 1, delay: 1}
39# skip_fail: false
40
41- description: Installing salt master on cfg01
42 cmd: eatmydata apt-get install -y reclass git salt-master
43 node_name: {{ HOSTNAME_CFG01 }}
44 retry: {count: 1, delay: 1}
45 skip_fail: false
46
47#- description: (moved to cloud-init config) Install common packages on cfg01
48# cmd: eatmydata apt-get install -y python-pip wget curl tmux byobu iputils-ping traceroute htop tree
49# node_name: {{ HOSTNAME_CFG01 }}
50# retry: {count: 1, delay: 1}
51# skip_fail: false
52
53- description: Configure salt-master on cfg01
54 cmd: |
55 cat << 'EOF' >> /etc/salt/master.d/master.conf
56 file_roots:
57 base:
58 - /usr/share/salt-formulas/env
59 pillar_opts: False
60 open_mode: True
61 reclass: &reclass
62 storage_type: yaml_fs
63 inventory_base_uri: /srv/salt/reclass
64 ext_pillar:
65 - reclass: *reclass
66 master_tops:
67 reclass: *reclass
68 EOF
69 node_name: {{ HOSTNAME_CFG01 }}
70 retry: {count: 1, delay: 1}
71 skip_fail: false
72
73- description: Configure GIT settings and certificates
74 cmd: touch /root/.git_trusted_certs.pem;
Matthew Mosesohnd0632b82017-05-30 17:51:30 +030075 for server in github.com; do
Dennis Dmitriev77d886c2017-05-24 13:13:26 +030076 openssl s_client -showcerts -connect $server:443 </dev/null
77 | openssl x509 -outform PEM
78 >> /root/.git_trusted_certs.pem;
79 done;
80 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
81 HOME=/root git config --global user.email "tcp-qa@example.com";
82 HOME=/root git config --global user.name "TCP QA";
83 node_name: {{ HOSTNAME_CFG01 }}
84 retry: {count: 1, delay: 1}
85 skip_fail: false
86
87
88- description: Clone reclass models with submodules
89 cmd: |
90 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Valentyn Yakovlev08acf9f2017-06-07 14:02:36 +030091 git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
92 pushd /srv/salt/reclass && git checkout {{ SALT_MODELS_COMMIT }} && popd;
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030093 {%- if SALT_MODELS_REF_CHANGE != '' %}
94 pushd /srv/salt/reclass && git fetch {{ SALT_MODELS_REPOSITORY }} {{ SALT_MODELS_REF_CHANGE }} && git checkout FETCH_HEAD && popd;
95 {%- endif %}
Dennis Dmitriev77d886c2017-05-24 13:13:26 +030096 mkdir -p /srv/salt/reclass/classes/service;
97
98 # Replace firstly to an intermediate value to avoid intersection between
99 # already replaced and replacing networks.
100 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
101 # 192.168.10 -> 10.16.0 (generated network for admin)
102 # 10.16.0 -> <external network>
103 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
104
105 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
106
107 # Disable checkouting the model from remote repository
108 cat << 'EOF' >> /srv/salt/reclass/nodes/control/{{ HOSTNAME_CFG01 }}.yml
109 # local storage
110 reclass:
111 storage:
112 data_source:
113 engine: local
114 EOF
115
116 # Show the changes to the console
117 cd /srv/salt/reclass/; git diff
118 node_name: {{ HOSTNAME_CFG01 }}
119 retry: {count: 1, delay: 1}
120 skip_fail: false
121
122- description: Configure reclass
123 cmd: |
124 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
125 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial stable salt};
126 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
127 which wget > /dev/null || (apt-get update; apt-get install -y wget);
128 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
129 wget -O - "${FORMULA_GPG}" | apt-key add -;
130 apt-get clean; apt-get update;
131 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich644446f2017-06-08 13:43:36 +0300132 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 +0300133 echo -e "\nInstalling all required salt formulas\n";
134 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
135 for formula_service in "${formula_services[@]}"; do
136 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
137 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
138 done;
139 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
140 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
141 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
142
143 cat << 'EOF' >> /etc/reclass/reclass-config.yml
144 storage_type: yaml_fs
145 pretty_print: True
146 output: yaml
147 inventory_base_uri: /srv/salt/reclass
148 EOF
149 node_name: {{ HOSTNAME_CFG01 }}
150 retry: {count: 1, delay: 1}
151 skip_fail: false
152
153- description: Restart salt-master service
154 cmd: |
Dennis Dmitriev266ec072017-05-25 13:39:17 +0300155 systemctl restart salt-master; sleep 60
Dennis Dmitriev77d886c2017-05-24 13:13:26 +0300156 node_name: {{ HOSTNAME_CFG01 }}
157 retry: {count: 1, delay: 5}
158 skip_fail: false
159
160{% for ssh in config.underlay.ssh %}
161- description: Configure salt-minion on {{ ssh['node_name'] }}
162 cmd: |
163 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
164 cat << "EOF" >> /etc/salt/minion.d/minion.conf
165 id: {{ ssh['node_name'] }}
166 master: {{ config.salt.salt_master_host }}
167 EOF
168 eatmydata apt-get install -y salt-minion;
169 echo "Check for system info and metadata availability ...";
170 salt-call --no-color grains.items;
171 salt-call --no-color pillar.items;
172 node_name: {{ ssh['node_name'] }}
173 retry: {count: 1, delay: 1}
174 skip_fail: false
175{% endfor %}
176
177
178- description: Accept salt keys from all the nodes
179 cmd: salt-key -A -y
180 node_name: {{ HOSTNAME_CFG01 }}
181 retry: {count: 1, delay: 5}
182 skip_fail: true
183
184
185- description: Configure salt adoptors on cfg01
186 cmd: |
187 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
188 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
189 node_name: {{ HOSTNAME_CFG01 }}
190 retry: {count: 1, delay: 1}
191 skip_fail: false
192
193
194# Prepare salt services and nodes settings
195- description: Run 'linux' formula on cfg01
196 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
197 -C 'I@salt:master' state.sls linux;
198 node_name: {{ HOSTNAME_CFG01 }}
199 retry: {count: 3, delay: 5}
200 skip_fail: false
201
202
203- description: Run 'openssh' formula on cfg01
204 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
205 -C 'I@salt:master' state.sls openssh;
206 salt --hard-crash --state-output=mixed --state-verbose=False
207 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
208 yes/' /etc/ssh/sshd_config && service ssh restart";
209 node_name: {{ HOSTNAME_CFG01 }}
210 retry: {count: 3, delay: 5}
211 skip_fail: false
212
213
214- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
215 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
216 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
217 node_name: {{ HOSTNAME_CFG01 }}
218 retry: {count: 1, delay: 1}
219 skip_fail: false
220
221- description: Run 'salt.master' formula on cfg01
222 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
223 -C 'I@salt:master' state.sls salt.master.service;
224 node_name: {{ HOSTNAME_CFG01 }}
225 retry: {count: 2, delay: 5}
226 skip_fail: false
227
228- description: Run 'salt' formula on cfg01 with workaround proposed in PROD-10894
229 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
230 -C 'I@salt:master' state.sls salt;
231 salt --hard-crash --state-output=mixed --state-verbose=False
232 -C 'I@salt:master' saltutil.sync_all
233 node_name: {{ HOSTNAME_CFG01 }}
234 retry: {count: 5, delay: 5}
235 skip_fail: false
236
237- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
238 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
239 -C 'I@salt:master' state.sls reclass
240 node_name: {{ HOSTNAME_CFG01 }}
241 retry: {count: 1, delay: 5}
242 skip_fail: false
243
244
245
Dennis Dmitrieve17bcaf2017-05-25 00:26:57 +0300246- description: Refresh pillars for present baremetal nodes
247 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
Dennis Dmitriev77d886c2017-05-24 13:13:26 +0300248 node_name: {{ HOSTNAME_CFG01 }}
249 retry: {count: 1, delay: 5}
250 skip_fail: false
251
Dennis Dmitrieve17bcaf2017-05-25 00:26:57 +0300252- description: Sync all salt resources for present baremetal nodes
253 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
254 node_name: {{ HOSTNAME_CFG01 }}
255 retry: {count: 1, delay: 5}
256 skip_fail: false
257
258- description: Configure linux for present baremetal nodes
259 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
260 cfg01*' state.sls linux
261 node_name: {{ HOSTNAME_CFG01 }}
262 retry: {count: 3, delay: 5}
263 skip_fail: false
264
265- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-9576 to get bond0-connectivity *without* rebooting nodes'
266 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' cmd.run
267 "cat /etc/network/interfaces | grep bond-slaves | awk '{print \$2}' | xargs -I {} ifenslave bond0 {}"
Dennis Dmitriev77d886c2017-05-24 13:13:26 +0300268 node_name: {{ HOSTNAME_CFG01 }}
269 retry: {count: 1, delay: 5}
270 skip_fail: false
271
272- description: ovs-dvr-vlan model specific Execute 'libvirt' states to create necessary libvirt networks
273 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'kvm*' state.sls libvirt
274 node_name: {{ HOSTNAME_CFG01 }}
275 retry: {count: 1, delay: 10}
276 skip_fail: false
277
278- description: Create VMs for control plane
279 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'kvm*' state.sls salt.control
280 node_name: {{ HOSTNAME_CFG01 }}
281 retry: {count: 3, delay: 10}
282 skip_fail: false
283
284
285
286- description: Refresh pillars on all minions
287 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
288 node_name: {{ HOSTNAME_CFG01 }}
289 retry: {count: 1, delay: 5}
290 skip_fail: false
291
292- description: Sync all salt resources
293 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
294 node_name: {{ HOSTNAME_CFG01 }}
295 retry: {count: 1, delay: 5}
296 skip_fail: false
297
298- description: Show reclass-salt --top for generated nodes
299 cmd: reclass-salt --top -u /srv/salt/reclass/nodes/_generated/
300 node_name: {{ HOSTNAME_CFG01 }}
301 retry: {count: 1, delay: 5}
302 skip_fail: false
303
304- description: Execute salt.minion.cert
305 cmd: salt-call --no-color state.sls salt.minion.cert -l info;
306 node_name: {{ HOSTNAME_CFG01 }}
307 retry: {count: 1, delay: 5}
308 skip_fail: false
309
310
311# Bootstrap all nodes
312
313- description: Configure linux on other nodes
314 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
315 cfg01*' state.sls linux
316 node_name: {{ HOSTNAME_CFG01 }}
317 retry: {count: 3, delay: 5}
318 skip_fail: false
319
320- description: Configure openssh on all nodes
321 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
322 cfg01*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
323 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
324 yes/' /etc/ssh/sshd_config && service ssh restart"
325 node_name: {{ HOSTNAME_CFG01 }}
326 retry: {count: 1, delay: 5}
327 skip_fail: false
328
329- description: Configure salt.minion on other nodes
330 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
331 cfg01*' state.sls salt.minion
332 node_name: {{ HOSTNAME_CFG01 }}
333 retry: {count: 3, delay: 5}
334 skip_fail: false
335
336- description: Check salt minion versions on slaves
337 cmd: salt '*' test.version
338 node_name: {{ HOSTNAME_CFG01 }}
339 retry: {count: 1, delay: 5}
340 skip_fail: false
341
342- description: Check salt top states on nodes
343 cmd: salt '*' state.show_top
344 node_name: {{ HOSTNAME_CFG01 }}
345 retry: {count: 1, delay: 5}
346 skip_fail: false
347
348- description: Configure ntp and rsyslog on nodes
349 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog
350 node_name: {{ HOSTNAME_CFG01 }}
351 retry: {count: 1, delay: 10}
352 skip_fail: false
353
354
355#- description: Hack gtw node
356# cmd: salt 'gtw*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4";
357# node_name: {{ HOSTNAME_CFG01 }}
358# retry: {count: 1, delay: 10}
359# skip_fail: false
360
361#- description: Hack cmp01 node
362# cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
363# node_name: {{ HOSTNAME_CFG01 }}
364# retry: {count: 1, delay: 10}
365# skip_fail: false
366
367#- description: Hack cmp02 node
368# cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
369# node_name: {{ HOSTNAME_CFG01 }}
370# retry: {count: 1, delay: 10}
371# skip_fail: false