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