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