blob: 5b13c2f4b93b09757c67139852ac512ac33e432a [file] [log] [blame]
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001{# Collection of common macroses shared across different deployments #}
2
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02003{% set SALT_MODELS_BRANCH = os_env('SALT_MODELS_BRANCH','master') %}
4{% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %}
5{# 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 #}
6{% set SALT_MODELS_REF_CHANGE = os_env('SALT_MODELS_REF_CHANGE', '') %}
7{# Pin to a specified commit in salt-models/reclass-system #}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +03008{% set SALT_MODELS_SYSTEM_REPOSITORY = os_env('SALT_MODELS_SYSTEM_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/reclass-system') %}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02009{% set SALT_MODELS_SYSTEM_COMMIT = os_env('SALT_MODELS_SYSTEM_COMMIT','') %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +030010{% set SALT_MODELS_SYSTEM_REF_CHANGE = os_env('SALT_MODELS_SYSTEM_REF_CHANGE','') %}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020011
Dennis Dmitriev492813e2017-08-09 15:08:58 +030012{% set REPOSITORY_SUITE = os_env('REPOSITORY_SUITE', 'testing') %}
13
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020014{# Address pools for reclass cluster model are taken in the following order:
15 # 1. environment variables,
16 # 2. config.underlay.address_pools based on fuel-devops address pools
17 # (see generated '.ini' file after underlay is created),
18 # 3. defaults #}
19{% set address_pools = config.underlay.address_pools %}
20{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
21{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
22{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
23{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
24{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
25{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
26{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
27{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
28
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040029{# Format for formula replacement:
30 # space separated string:
31 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
32
33{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
34{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.net/salt-formulas') %}
35
Dennis Dmitriev492813e2017-08-09 15:08:58 +030036
37{%- macro MACRO_INSTALL_SALT_MASTER() %}
38{######################################}
39- description: Installing salt master on cfg01
40 cmd: eatmydata apt-get install -y reclass git salt-master
41 node_name: {{ HOSTNAME_CFG01 }}
42 retry: {count: 1, delay: 1}
43 skip_fail: false
44
45- description: Configure salt-master on cfg01
46 cmd: |
47 cat << 'EOF' >> /etc/salt/master.d/master.conf
48 file_roots:
49 base:
50 - /usr/share/salt-formulas/env
51 pillar_opts: False
52 open_mode: True
53 reclass: &reclass
54 storage_type: yaml_fs
55 inventory_base_uri: /srv/salt/reclass
56 ext_pillar:
57 - reclass: *reclass
58 master_tops:
59 reclass: *reclass
60 EOF
61 node_name: {{ HOSTNAME_CFG01 }}
62 retry: {count: 1, delay: 1}
63 skip_fail: false
64
65- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +030066 cmd: |
67 set -e;
68 touch /root/.git_trusted_certs.pem;
69 for server in github.com; do \
70 openssl s_client -showcerts -connect $server:443 </dev/null \
71 | openssl x509 -outform PEM \
Dennis Dmitriev492813e2017-08-09 15:08:58 +030072 >> /root/.git_trusted_certs.pem;
73 done;
74 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
75 HOME=/root git config --global user.email "tcp-qa@example.com";
76 HOME=/root git config --global user.name "TCP QA";
77 node_name: {{ HOSTNAME_CFG01 }}
78 retry: {count: 1, delay: 1}
79 skip_fail: false
80{%- endmacro %}
81
82
83{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false) %}
84{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +030085{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
86
Dennis Dmitriev492813e2017-08-09 15:08:58 +030087- description: Clone reclass models with submodules
88 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +030089 set -e;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020090 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Tatyana Leontovich44162732017-08-28 12:36:00 +030091 export GIT_SSL_NO_VERIFY=true; git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020092 pushd /srv/salt/reclass && \
93 {%- if SALT_MODELS_REF_CHANGE != '' %}
94 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
95 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD && \
96 {%- endfor %}
97 {%- elif SALT_MODELS_COMMIT != 'master' %}
98 git checkout {{ SALT_MODELS_COMMIT }} && \
99 {%- endif %}
100 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
101 pushd classes/system/ && \
102 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
103 popd && \
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300104 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' -%}
105 pushd classes/system/ && \
106 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
107 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD && \
108 {%- endfor %}
109 popd && \
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200110 {%- else %}
111 git submodule update --init --recursive && \
112 {%- endif %}
113 popd;
114 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitriev803327f2017-09-26 20:42:01 +0300115 mkdir -p /srv/salt/reclass/nodes;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200116
117 # Replace firstly to an intermediate value to avoid intersection between
118 # already replaced and replacing networks.
119 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
120 # 192.168.10 -> 10.16.0 (generated network for admin)
121 # 10.16.0 -> <external network>
122 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300123 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
124 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
125 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
126 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} +
127 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200128
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300129 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
130 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
131 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} +
132 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200133
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300134 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200135
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300136 {%- if IS_CONTRAIL_LAB %}
137 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300138 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
Tatyana Leontovich3424bf62017-09-15 12:13:54 +0300139 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300140 {%- endif %}
141
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200142 # Disable checkouting the model from remote repository
143 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
144 # local storage
145 reclass:
146 storage:
147 data_source:
148 engine: local
149 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300150
151 # Show the changes to the console
152 cd /srv/salt/reclass/; git diff
153 node_name: {{ HOSTNAME_CFG01 }}
154 retry: {count: 1, delay: 1}
155 skip_fail: false
156{%- endmacro %}
157
158
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300159{%- macro MACRO_GENERATE_COOKIECUTTER_MODELS(IS_CONTRAIL_LAB=false) %}
160{############################################################}
161- description: "[EXPERIMENTAL] Upload 'environment' to {{ HOSTNAME_CFG01 }}"
162 upload:
163 local_path: {{ config.salt_deploy.environment_template_dir }}
164 remote_path: /tmp/environment/
165 node_name: {{ HOSTNAME_CFG01 }}
166 skip_fail: false
167
168- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to {{ HOSTNAME_CFG01 }}"
169 upload:
170 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
171 local_filename: salt-context-cicd_oss.yaml
172 remote_path: /tmp/environment/
173 node_name: {{ HOSTNAME_CFG01 }}
174
175- description: "[EXPERIMENTAL] Upload environment inventory to {{ HOSTNAME_CFG01 }}"
176 upload:
177 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
178 local_filename: salt-context-environment.yaml
179 remote_path: /tmp/environment/
180 node_name: {{ HOSTNAME_CFG01 }}
181
182- description: Create cluster model from cookiecutter templates
183 cmd: |
184 set -e;
185 pip install cookiecutter
186 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates /tmp/cookiecutter-templates
187 mkdir -p /srv/salt/reclass/classes/cluster/
188 mkdir -p /srv/salt/reclass/classes/system/
189 mkdir -p /srv/salt/reclass/classes/service/
190 mkdir -p /srv/salt/reclass/nodes/_generated
191
192 # Override some context parameters
193 sed -i 's/cluster_name:.*/cluster_name: {{ LAB_CONFIG_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
194 sed -i 's/cluster_domain:.*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
195 sed -i 's/control_vlan:.*/control_vlan: \"2416\"/g' {{ CLUSTER_CONTEXT_PATH }}
196 sed -i 's/tenant_vlan:.*/tenant_vlan: \"2417\"/g' {{ CLUSTER_CONTEXT_PATH }}
197
198 # Temporary workaround (with hardcoded address .90 -> .15) of bug https://mirantis.jira.com/browse/PROD-14377
Dennis Dmitriev39e64bd2017-09-21 22:37:40 +0300199 sed -i 's/salt_master_address:.*/salt_master_address: {{ IPV4_NET_CONTROL_PREFIX }}.15/g' {{ CLUSTER_CONTEXT_PATH }}
200 sed -i 's/salt_master_management_address:.*/salt_master_management_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300201
202 # Replace firstly to an intermediate value to avoid intersection between
203 # already replaced and replacing networks.
204 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
205 # 192.168.10 -> 10.16.0 (generated network for admin)
206 # 10.16.0 -> <external network>
207 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
208 sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
209 sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
210 sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
211 sed -i 's/172\.17\.16\./==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
212
Dennis Dmitriev39e64bd2017-09-21 22:37:40 +0300213 sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
214 sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
215 sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
216 sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300217
218 for i in $(ls /tmp/cookiecutter-templates/cluster_product/); do
219 python /tmp/cookiecutter-templates/generate.py \
220 --template /tmp/cookiecutter-templates/cluster_product/$i \
221 --config-file {{ CLUSTER_CONTEXT_PATH }} \
222 --output-dir /srv/salt/reclass/classes/cluster/;
223 done
224
225 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/
226
227 # Create the cfg01 node and disable checkouting the model from remote repository
228 cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml
229 classes:
230 - system.openssh.server.team.all
231 - cluster.{{ LAB_CONFIG_NAME }}.infra.config
232 - environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local
233 - environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
234 EOF
235
236 node_name: {{ HOSTNAME_CFG01 }}
237 retry: {count: 1, delay: 1}
238 skip_fail: false
239
240- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
241 cmd: |
242 set -e;
243 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
244 pip install git+https://github.com/dis-xcom/reclass-tools;
245 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
246 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
247 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
248
249 #if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
250 # reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml --merge ;
251 #fi;
252
253 node_name: {{ HOSTNAME_CFG01 }}
254 retry: {count: 1, delay: 5}
255 skip_fail: false
256
257- description: "Workaround for PROD-14756: all roles must use service.keepalived.cluster.single with the default 'VIP' instance"
258 cmd: |
259 set -e;
260 find /srv/salt/reclass/classes/cluster/ -type f -exec sed -i 's/system.keepalived.*/service.keepalived.cluster.single/g' {} +
261 find /srv/salt/reclass/classes/system/ -type f -exec sed -i 's/system.keepalived.*/service.keepalived.cluster.single/g' {} +
262
263 node_name: {{ HOSTNAME_CFG01 }}
264 retry: {count: 1, delay: 5}
265 skip_fail: false
266
267- description: "[EXPERIMENTAL] Create environment model for virtual environment"
268 cmd: |
269 set -e;
270 ln -s '/tmp/environment/environment_template/{{ '{# interfaces #}' }}' '/tmp/environment/environment_template/{{ '{{ cookiecutter._env_name }}' }}/';
271 ln -s '/tmp/environment/environment_template/{{ '{# roles #}' }}' '/tmp/environment/environment_template/{{ '{{ cookiecutter._env_name }}' }}/';
272 reclass-tools render --template-dir /tmp/environment/environment_template/ \
273 --output-dir /srv/salt/reclass/classes/environment/ \
274 --context {{ ENVIRONMENT_CONTEXT_PATH }} \
275 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
276 node_name: {{ HOSTNAME_CFG01 }}
277 retry: {count: 1, delay: 5}
278 skip_fail: false
279
280- description: Modify generated model and reclass-system if necessary
281 cmd: |
282 set -e;
283 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
284 pushd /srv/salt/reclass/classes/system/
285 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
286 popd
287 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' -%}
288 pushd /srv/salt/reclass/classes/system/
289 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
290 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD
291 {%- endfor %}
292 popd
293 {%- endif %}
294
295 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
296 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
297
298 {%- if IS_CONTRAIL_LAB %}
299 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
300 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
301 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
302 {%- endif %}
303
304 node_name: {{ HOSTNAME_CFG01 }}
305 retry: {count: 1, delay: 1}
306 skip_fail: false
307{%- endmacro %}
308
309
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300310{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
311{#######################################################}
312- description: Configure reclass
313 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300314 set -e;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300315 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
316 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
317 FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg};
318 which wget > /dev/null || (apt-get update; apt-get install -y wget);
319 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
320 wget -O - "${FORMULA_GPG}" | apt-key add -;
321 apt-get clean; apt-get update;
322 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
323 declare -a formula_services=({{ FORMULA_SERVICES }});
324 echo -e "\nInstalling all required salt formulas\n";
325 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
326 for formula_service in "${formula_services[@]}"; do
327 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
328 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
329 done;
330 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
331 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
332 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
333
334 cat << 'EOF' >> /etc/reclass/reclass-config.yml
335 storage_type: yaml_fs
336 pretty_print: True
337 output: yaml
338 inventory_base_uri: /srv/salt/reclass
339 EOF
340 node_name: {{ HOSTNAME_CFG01 }}
341 retry: {count: 1, delay: 1}
342 skip_fail: false
343
344- description: "*Workaround* remove all cfg01 nodes except {{ HOSTNAME_CFG01 }} to not depend on other clusters in 'reclass --top'"
345 cmd: |
346 # Remove all other nodes except {{ HOSTNAME_CFG01 }} to not rely on them for 'reclass --top'
347 find /srv/salt/reclass/nodes/ -type f -not -name {{ HOSTNAME_CFG01 }}.yml -delete
348 node_name: {{ HOSTNAME_CFG01 }}
349 retry: {count: 1, delay: 5}
350 skip_fail: false
351
352- description: Configure salt adoptors on cfg01
353 cmd: |
354 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
355 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
356 node_name: {{ HOSTNAME_CFG01 }}
357 retry: {count: 1, delay: 1}
358 skip_fail: false
359
360- description: Show reclass-salt --top for cfg01 node
361 cmd: reclass-salt --top
362 node_name: {{ HOSTNAME_CFG01 }}
363 retry: {count: 1, delay: 5}
364 skip_fail: false
365
366- description: Restart salt-master service
367 cmd: systemctl restart salt-master;
368 node_name: {{ HOSTNAME_CFG01 }}
369 retry: {count: 1, delay: 5}
370 skip_fail: false
371{%- endmacro %}
372
373
374{%- macro MACRO_INSTALL_SALT_MINIONS() %}
375{#######################################}
376{% for ssh in config.underlay.ssh %}
377- description: Configure salt-minion on {{ ssh['node_name'] }}
378 cmd: |
379 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
380 cat << "EOF" >> /etc/salt/minion.d/minion.conf
381 id: {{ ssh['node_name'] }}
382 master: {{ config.salt.salt_master_host }}
383 EOF
384 eatmydata apt-get install -y salt-minion;
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300385 service salt-minion restart; # For case if salt-minion was already installed
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300386 node_name: {{ ssh['node_name'] }}
387 retry: {count: 1, delay: 1}
388 skip_fail: false
389{% endfor %}
390
391
392- description: Accept salt keys from all the nodes
393 cmd: salt-key -A -y
394 node_name: {{ HOSTNAME_CFG01 }}
395 retry: {count: 1, delay: 5}
396 skip_fail: true
397{%- endmacro %}
398
399
400{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
401{##################################################}
402
403{# Prepare salt services and nodes settings #}
404
405- description: Run 'linux' formula on cfg01
406 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
407 node_name: {{ HOSTNAME_CFG01 }}
408 retry: {count: 3, delay: 5}
409 skip_fail: false
410
411- description: Run 'openssh' formula on cfg01
412 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300413 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300414 salt --hard-crash --state-output=mixed --state-verbose=False
415 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300416 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300417 node_name: {{ HOSTNAME_CFG01 }}
418 retry: {count: 3, delay: 5}
419 skip_fail: false
420
421- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
422 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
423 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
424 node_name: {{ HOSTNAME_CFG01 }}
425 retry: {count: 1, delay: 1}
426 skip_fail: false
427
428- description: Run 'salt.master' formula on cfg01
429 cmd: timeout 120 salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
430 node_name: {{ HOSTNAME_CFG01 }}
431 retry: {count: 2, delay: 5}
432 skip_fail: false
433
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400434{%- if SALT_FORMULAS_REFS != '' %}
435- description: Replace needed formulas to desired version
436 cmd: |
437 set -e;
438 {%- for formula in SALT_FORMULAS_REFS.split(' ') %}
439 {% set formula_name = formula.0 %}
440 {% set formula_ref = formula.1 %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300441 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400442 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
443 pushd {{ formula_dir }} &&
444 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
445 git checkout FETCH_HEAD &&
446 popd &&
447 if [ -d "{{ formula_dir }}" ]; then
448 echo "Going to replace packaged formula {{ formula_name }}" &&
449 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
450 ln -v -s \"{{ formula_dir }}/{{ formula_name }}\" \"/usr/share/salt-formulas/env/{{ formula_name }}\" &&
451 ln -v -s \"{{ formula_dir }}/metadata/service/\" \"/usr/share/salt-formulas/reclass/service/{{ formula_name }}\";
452 else
453 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
454 fi
455 {%- endfor %}
456 node_name: {{ HOSTNAME_CFG01 }}
457 retry: {count: 1, delay: 10}
458 skip_fail: false
459{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300460
461- description: Refresh pillars on salt-master minion
462 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
463 node_name: {{ HOSTNAME_CFG01 }}
464 retry: {count: 1, delay: 5}
465 skip_fail: false
466
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300467- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300468 cmd: reclass-salt --top
469 node_name: {{ HOSTNAME_CFG01 }}
470 retry: {count: 1, delay: 5}
471 skip_fail: false
472
473- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300474 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300475 node_name: {{ HOSTNAME_CFG01 }}
476 retry: {count: 1, delay: 5}
477 skip_fail: false
478
479- description: Configure linux on master
480 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
481 node_name: {{ HOSTNAME_CFG01 }}
482 retry: {count: 1, delay: 5}
483 skip_fail: false
484
485- description: Configure salt.minion on master
486 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
487 -C 'I@salt:master' state.sls salt.minion && sleep 10
488 node_name: {{ HOSTNAME_CFG01 }}
489 retry: {count: 3, delay: 10}
490 skip_fail: false
491
492- description: Run state 'salt' on master (for salt.api, etc)
493 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
494 -C 'I@salt:master' state.sls salt
495 node_name: {{ HOSTNAME_CFG01 }}
496 retry: {count: 3, delay: 10}
497 skip_fail: false
498{%- endmacro %}
499
500{%- macro MACRO_GENERATE_INVENTORY() %}
501{#####################################}
502- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
503 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
504 -C 'I@salt:master' state.sls reclass
505 node_name: {{ HOSTNAME_CFG01 }}
506 retry: {count: 1, delay: 5}
507 skip_fail: false
508
509- description: Refresh pillars on all minions
510 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
511 node_name: {{ HOSTNAME_CFG01 }}
512 retry: {count: 1, delay: 5}
513 skip_fail: false
514
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300515- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300516 cmd: |
517 set -e
518 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
519 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
520 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300521 node_name: {{ HOSTNAME_CFG01 }}
522 retry: {count: 1, delay: 5}
523 skip_fail: false
524
525- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300526 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300527 node_name: {{ HOSTNAME_CFG01 }}
528 retry: {count: 1, delay: 5}
529 skip_fail: false
530{%- endmacro %}
531
532
533{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
534{########################################}
535# Bootstrap all nodes
536- description: Configure linux on other nodes
537 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
538 node_name: {{ HOSTNAME_CFG01 }}
539 retry: {count: 5, delay: 10}
540 skip_fail: false
541
542- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300543 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300544 salt --hard-crash --state-output=mixed --state-verbose=False
545 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
546 yes/' /etc/ssh/sshd_config && service ssh reload"
547 node_name: {{ HOSTNAME_CFG01 }}
548 retry: {count: 1, delay: 5}
549 skip_fail: false
550
551- description: Configure salt.minion on other nodes
552 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion &&
553 sleep 10
554 node_name: {{ HOSTNAME_CFG01 }}
555 retry: {count: 3, delay: 15}
556 skip_fail: false
557
558- description: Check salt minion versions on slaves
559 cmd: salt '*' test.version
560 node_name: {{ HOSTNAME_CFG01 }}
561 retry: {count: 3, delay: 15}
562 skip_fail: false
563
564- description: Check salt top states on nodes
565 cmd: salt '*' state.show_top
566 node_name: {{ HOSTNAME_CFG01 }}
567 retry: {count: 1, delay: 5}
568 skip_fail: false
569
570- description: Configure ntp and rsyslog on nodes
571 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
572 node_name: {{ HOSTNAME_CFG01 }}
573 retry: {count: 1, delay: 10}
574 skip_fail: false
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200575{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300576
577
578{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
579{#########################################}
580
581- description: '*Workaround 1/2* of the bug PROD-9576 to get bond0-connectivity *without* rebooting nodes'
582 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False cmd.run
583 "mkdir -p /tmp/PROD-9576; cd /tmp/PROD-9576; git clone https://gerrit.mcp.mirantis.net/salt-formulas/linux; cd linux;
Dennis Dmitrievec2bba62017-09-21 17:01:16 +0300584 git fetch https://gerrit.mcp.mirantis.net/salt-formulas/linux refs/changes/54/2354/16 && git checkout FETCH_HEAD;
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300585 cp -f linux/network/interface.sls /srv/salt/env/prd/linux/network/;
586 cp -f linux/map.jinja /srv/salt/env/prd/linux/;"
587 node_name: {{ HOSTNAME_CFG01 }}
588 retry: {count: 1, delay: 5}
589 skip_fail: false
590
591- description: '*Workaround: Load bonding module before call state.linux'
592 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
593 node_name: {{ HOSTNAME_CFG01 }}
594 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +0300595 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300596
597- description: '*Workaround* install bridge-utils before running linux formula'
598 # The formula removes default route and then tries to install the package, fails.
599 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
600 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
601 node_name: {{ HOSTNAME_CFG01 }}
602 retry: {count: 1, delay: 5}
603 skip_fail: false
604
605{%- endmacro %}