blob: fd113ee94b1ff7e9cd80f8855751b8db8e31e112 [file] [log] [blame]
Dennis Dmitrievab83ea42017-05-12 16:52:45 +03001{% from 'virtual-mcp-ocata-dvr/underlay.yaml' import HOSTNAME_CFG01 with context %}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +03002{% from 'virtual-mcp-ocata-dvr/underlay.yaml' import REPOSITORY_SUITE with context %}
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +03003
4{% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab') %}
Valentyn Yakovlev08acf9f2017-06-07 14:02:36 +03005{% set SALT_MODELS_BRANCH = os_env('SALT_MODELS_BRANCH','master') %}
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +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 Dmitriev99b26fe2017-04-26 12:34:44 +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{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
18{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
19{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
20{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
21
22{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
23{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
24{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
25{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030026
27# Install salt to the config node
28
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030029- description: Installing salt master on cfg01
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030030 cmd: eatmydata apt-get install -y reclass git salt-master
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030031 node_name: {{ HOSTNAME_CFG01 }}
32 retry: {count: 1, delay: 1}
33 skip_fail: false
34
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030035- description: Configure salt-master on cfg01
36 cmd: |
37 cat << 'EOF' >> /etc/salt/master.d/master.conf
38 file_roots:
39 base:
40 - /usr/share/salt-formulas/env
41 pillar_opts: False
42 open_mode: True
43 reclass: &reclass
44 storage_type: yaml_fs
45 inventory_base_uri: /srv/salt/reclass
46 ext_pillar:
47 - reclass: *reclass
48 master_tops:
49 reclass: *reclass
50 EOF
51 node_name: {{ HOSTNAME_CFG01 }}
52 retry: {count: 1, delay: 1}
53 skip_fail: false
54
55- description: Configure GIT settings and certificates
56 cmd: touch /root/.git_trusted_certs.pem;
57 for server in git.tcpcloud.eu github.com; do
58 openssl s_client -showcerts -connect $server:443 </dev/null
59 | openssl x509 -outform PEM
60 >> /root/.git_trusted_certs.pem;
61 done;
62 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
63 HOME=/root git config --global user.email "tcp-qa@example.com";
64 HOME=/root git config --global user.name "TCP QA";
65 node_name: {{ HOSTNAME_CFG01 }}
66 retry: {count: 1, delay: 1}
67 skip_fail: false
68
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030069- description: Clone reclass models with submodules
70 cmd: |
71 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Valentyn Yakovlev08acf9f2017-06-07 14:02:36 +030072 git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
73 pushd /srv/salt/reclass && git checkout {{ SALT_MODELS_COMMIT }} && popd;
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030074 {%- if SALT_MODELS_REF_CHANGE != '' %}
75 pushd /srv/salt/reclass && git fetch {{ SALT_MODELS_REPOSITORY }} {{ SALT_MODELS_REF_CHANGE }} && git checkout FETCH_HEAD && popd;
76 {%- endif %}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030077 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030078
79 # Replace firstly to an intermediate value to avoid intersection between
80 # already replaced and replacing networks.
81 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
82 # 192.168.10 -> 10.16.0 (generated network for admin)
83 # 10.16.0 -> <external network>
84 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
85 find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
86 find /srv/salt/reclass/ -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
87 find /srv/salt/reclass/ -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} +
88 find /srv/salt/reclass/ -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
89
90 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
91 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
92 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} +
93 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {} +
94
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +030095 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
96
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030097 # Disable checkouting the model from remote repository
98 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
99 # local storage
100 reclass:
101 storage:
102 data_source:
103 engine: local
104 EOF
105
106 # Show the changes to the console
107 cd /srv/salt/reclass/; git diff
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300108 node_name: {{ HOSTNAME_CFG01 }}
109 retry: {count: 1, delay: 1}
110 skip_fail: false
111
112- description: Configure reclass
113 cmd: |
114 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
obutenko89aedf82017-08-04 12:50:37 +0300115 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
116 FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg};
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300117 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Tatyana Leontovich543afa92017-04-21 14:48:03 +0300118 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300119 wget -O - "${FORMULA_GPG}" | apt-key add -;
120 apt-get clean; apt-get update;
121 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitriev76f65462017-07-20 16:21:26 -0400122 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch" "powerdns");
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300123 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300124 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300125 for formula_service in "${formula_services[@]}"; do
126 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
127 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
128 done;
129 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
130 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
131 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
132
133 cat << 'EOF' >> /etc/reclass/reclass-config.yml
134 storage_type: yaml_fs
135 pretty_print: True
136 output: yaml
137 inventory_base_uri: /srv/salt/reclass
138 EOF
139 node_name: {{ HOSTNAME_CFG01 }}
140 retry: {count: 1, delay: 1}
141 skip_fail: false
142
Dennis Dmitriev9c2707e2017-07-21 13:17:53 +0300143- description: "*Workaround* remove all cfg01 nodes except {{ HOSTNAME_CFG01 }} to not depend on other clusters in 'reclass --top'"
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300144 cmd: |
Dennis Dmitriev9c2707e2017-07-21 13:17:53 +0300145 # Remove all other nodes except {{ HOSTNAME_CFG01 }} to not rely on them for 'reclass --top'
146 find /srv/salt/reclass/nodes/ -type f -not -name {{ HOSTNAME_CFG01 }}.yml -delete
147 node_name: {{ HOSTNAME_CFG01 }}
148 retry: {count: 1, delay: 5}
149 skip_fail: false
150
151- description: Show reclass-salt --top for cfg01 node
152 cmd: reclass-salt --top
153 node_name: {{ HOSTNAME_CFG01 }}
154 retry: {count: 1, delay: 5}
155 skip_fail: false
156
157- description: Restart salt-master service
158 cmd: systemctl restart salt-master;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300159 node_name: {{ HOSTNAME_CFG01 }}
160 retry: {count: 1, delay: 5}
161 skip_fail: false
162
163{% for ssh in config.underlay.ssh %}
164- description: Configure salt-minion on {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300165 cmd: |
166 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
167 cat << "EOF" >> /etc/salt/minion.d/minion.conf
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300168 id: {{ ssh['node_name'] }}
169 master: {{ config.salt.salt_master_host }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300170 EOF
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300171 eatmydata apt-get install -y salt-minion;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300172 echo "Check for system info and metadata availability ...";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300173 salt-call --no-color grains.items;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300174 salt-call --no-color pillar.items;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300175 node_name: {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300176 retry: {count: 1, delay: 1}
177 skip_fail: false
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300178{% endfor %}
179
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300180- description: Accept salt keys from all the nodes
181 cmd: salt-key -A -y
182 node_name: {{ HOSTNAME_CFG01 }}
183 retry: {count: 1, delay: 5}
184 skip_fail: true
185
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300186- description: Configure salt adoptors on cfg01
187 cmd: |
188 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
189 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
190 node_name: {{ HOSTNAME_CFG01 }}
191 retry: {count: 1, delay: 1}
192 skip_fail: false
193
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300194# Prepare salt services and nodes settings
195- description: Run 'linux' formula on cfg01
Tatyana Leontovich18013122017-06-09 20:24:50 +0300196 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300197 node_name: {{ HOSTNAME_CFG01 }}
198 retry: {count: 1, delay: 5}
199 skip_fail: false
200
201- description: Run 'openssh' formula on cfg01
202 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
203 -C 'I@salt:master' state.sls openssh;
204 salt --hard-crash --state-output=mixed --state-verbose=False
205 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Tatyana Leontovich18013122017-06-09 20:24:50 +0300206 yes/' /etc/ssh/sshd_config && service ssh reload";
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300207 node_name: {{ HOSTNAME_CFG01 }}
208 retry: {count: 3, delay: 5}
209 skip_fail: false
210
211- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
212 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
213 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
214 node_name: {{ HOSTNAME_CFG01 }}
215 retry: {count: 1, delay: 1}
216 skip_fail: false
217
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300218- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve4cfced2017-07-27 07:31:21 +0300219 cmd: timeout 120 salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300220 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300221 retry: {count: 2, delay: 5}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300222 skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300223
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300224- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
225 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
226 -C 'I@salt:master' state.sls reclass
227 node_name: {{ HOSTNAME_CFG01 }}
228 retry: {count: 1, delay: 5}
229 skip_fail: false
230
231- description: Refresh pillars on all minions
232 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
233 node_name: {{ HOSTNAME_CFG01 }}
234 retry: {count: 1, delay: 5}
235 skip_fail: false
236
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300237- description: Show reclass-salt --top
Dennis Dmitriev9c2707e2017-07-21 13:17:53 +0300238 cmd: reclass-salt --top
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300239 node_name: {{ HOSTNAME_CFG01 }}
240 retry: {count: 1, delay: 5}
241 skip_fail: false
242
Tatyana Leontovich18013122017-06-09 20:24:50 +0300243- description: Sync all salt resources
244 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300245 node_name: {{ HOSTNAME_CFG01 }}
246 retry: {count: 1, delay: 5}
247 skip_fail: false
248
Tatyana Leontovich18013122017-06-09 20:24:50 +0300249- description: Configure linux on master
250 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
251 node_name: {{ HOSTNAME_CFG01 }}
252 retry: {count: 1, delay: 5}
253 skip_fail: false
254
255- description: Configure minion on master
Dennis Dmitriev980db162017-07-27 09:40:01 +0300256 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovich18013122017-06-09 20:24:50 +0300257 -C 'I@salt:master' state.sls 'salt.minion'
258 node_name: {{ HOSTNAME_CFG01 }}
259 retry: {count: 3, delay: 10}
260 skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300261
262# Bootstrap all nodes
263
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300264- description: Configure linux on other nodes
Tatyanka Leontovichbbd6b2d2017-07-21 06:02:15 -0400265 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls 'linux'
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300266 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve4cfced2017-07-27 07:31:21 +0300267 retry: {count: 3, delay: 5}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300268 skip_fail: false
269
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300270- description: Configure openssh on all nodes
Tatyanka Leontovichbbd6b2d2017-07-21 06:02:15 -0400271 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls openssh;
Tatyana Leontovich18013122017-06-09 20:24:50 +0300272 salt --hard-crash --state-output=mixed --state-verbose=False
Tatyanka Leontovichbbd6b2d2017-07-21 06:02:15 -0400273 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Tatyana Leontovich18013122017-06-09 20:24:50 +0300274 yes/' /etc/ssh/sshd_config && service ssh reload"
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300275 node_name: {{ HOSTNAME_CFG01 }}
276 retry: {count: 1, delay: 5}
277 skip_fail: false
278
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300279- description: Configure salt.minion on other nodes
Dennis Dmitriev980db162017-07-27 09:40:01 +0300280 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300281 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev5b0e5f32017-07-22 11:30:26 +0300282 retry: {count: 3, delay: 15}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300283 skip_fail: false
284
285- description: Check salt minion versions on slaves
286 cmd: salt '*' test.version
287 node_name: {{ HOSTNAME_CFG01 }}
288 retry: {count: 1, delay: 5}
289 skip_fail: false
290
291- description: Check salt top states on nodes
292 cmd: salt '*' state.show_top
293 node_name: {{ HOSTNAME_CFG01 }}
294 retry: {count: 1, delay: 5}
295 skip_fail: false
296
297- description: Configure ntp and rsyslog on nodes
Tatyanka Leontovichbbd6b2d2017-07-21 06:02:15 -0400298 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300299 node_name: {{ HOSTNAME_CFG01 }}
300 retry: {count: 1, delay: 10}
301 skip_fail: false
302
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300303- description: Hack gtw node
304 cmd: salt 'gtw*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4";
305 node_name: {{ HOSTNAME_CFG01 }}
306 retry: {count: 1, delay: 10}
307 skip_fail: false
308
309- description: Hack cmp01 node
310 cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
311 node_name: {{ HOSTNAME_CFG01 }}
312 retry: {count: 1, delay: 10}
313 skip_fail: false
314
315- description: Hack cmp02 node
316 cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
317 node_name: {{ HOSTNAME_CFG01 }}
318 retry: {count: 1, delay: 10}
319 skip_fail: false