blob: 78ecf857bbce626407f5bb0a83d9ace35446fb23 [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 Dmitrievb2e78be2017-09-26 23:25:24 +0300115 mkdir -p /srv/salt/reclass/nodes/_generated/;
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
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300143 cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml
144 classes:
145 - cluster.{{ LAB_CONFIG_NAME }}.infra.config
146 parameters:
147 _param:
148 linux_system_codename: xenial
149 reclass_data_revision: master
150 linux:
151 system:
152 name: cfg01
153 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200154 reclass:
155 storage:
156 data_source:
157 engine: local
158 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300159
160 # Show the changes to the console
161 cd /srv/salt/reclass/; git diff
162 node_name: {{ HOSTNAME_CFG01 }}
163 retry: {count: 1, delay: 1}
164 skip_fail: false
165{%- endmacro %}
166
167
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300168{%- macro MACRO_GENERATE_COOKIECUTTER_MODELS(IS_CONTRAIL_LAB=false) %}
169{############################################################}
170- description: "[EXPERIMENTAL] Upload 'environment' to {{ HOSTNAME_CFG01 }}"
171 upload:
172 local_path: {{ config.salt_deploy.environment_template_dir }}
173 remote_path: /tmp/environment/
174 node_name: {{ HOSTNAME_CFG01 }}
175 skip_fail: false
176
177- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to {{ HOSTNAME_CFG01 }}"
178 upload:
179 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
180 local_filename: salt-context-cicd_oss.yaml
181 remote_path: /tmp/environment/
182 node_name: {{ HOSTNAME_CFG01 }}
183
184- description: "[EXPERIMENTAL] Upload environment inventory to {{ HOSTNAME_CFG01 }}"
185 upload:
186 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
187 local_filename: salt-context-environment.yaml
188 remote_path: /tmp/environment/
189 node_name: {{ HOSTNAME_CFG01 }}
190
191- description: Create cluster model from cookiecutter templates
192 cmd: |
193 set -e;
194 pip install cookiecutter
195 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates /tmp/cookiecutter-templates
196 mkdir -p /srv/salt/reclass/classes/cluster/
197 mkdir -p /srv/salt/reclass/classes/system/
198 mkdir -p /srv/salt/reclass/classes/service/
199 mkdir -p /srv/salt/reclass/nodes/_generated
200
201 # Override some context parameters
202 sed -i 's/cluster_name:.*/cluster_name: {{ LAB_CONFIG_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
203 sed -i 's/cluster_domain:.*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
204 sed -i 's/control_vlan:.*/control_vlan: \"2416\"/g' {{ CLUSTER_CONTEXT_PATH }}
205 sed -i 's/tenant_vlan:.*/tenant_vlan: \"2417\"/g' {{ CLUSTER_CONTEXT_PATH }}
206
207 # Temporary workaround (with hardcoded address .90 -> .15) of bug https://mirantis.jira.com/browse/PROD-14377
Dennis Dmitriev39e64bd2017-09-21 22:37:40 +0300208 sed -i 's/salt_master_address:.*/salt_master_address: {{ IPV4_NET_CONTROL_PREFIX }}.15/g' {{ CLUSTER_CONTEXT_PATH }}
209 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 +0300210
211 # Replace firstly to an intermediate value to avoid intersection between
212 # already replaced and replacing networks.
213 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
214 # 192.168.10 -> 10.16.0 (generated network for admin)
215 # 10.16.0 -> <external network>
216 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
217 sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
218 sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
219 sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
220 sed -i 's/172\.17\.16\./==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
221
Dennis Dmitriev39e64bd2017-09-21 22:37:40 +0300222 sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
223 sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
224 sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
225 sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300226
227 for i in $(ls /tmp/cookiecutter-templates/cluster_product/); do
228 python /tmp/cookiecutter-templates/generate.py \
229 --template /tmp/cookiecutter-templates/cluster_product/$i \
230 --config-file {{ CLUSTER_CONTEXT_PATH }} \
231 --output-dir /srv/salt/reclass/classes/cluster/;
232 done
233
234 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/
235
236 # Create the cfg01 node and disable checkouting the model from remote repository
237 cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml
238 classes:
239 - system.openssh.server.team.all
240 - cluster.{{ LAB_CONFIG_NAME }}.infra.config
241 - environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local
242 - environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
243 EOF
244
245 node_name: {{ HOSTNAME_CFG01 }}
246 retry: {count: 1, delay: 1}
247 skip_fail: false
248
249- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
250 cmd: |
251 set -e;
252 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
253 pip install git+https://github.com/dis-xcom/reclass-tools;
254 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
255 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
256 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
257
258 #if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
259 # reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml --merge ;
260 #fi;
261
262 node_name: {{ HOSTNAME_CFG01 }}
263 retry: {count: 1, delay: 5}
264 skip_fail: false
265
266- description: "Workaround for PROD-14756: all roles must use service.keepalived.cluster.single with the default 'VIP' instance"
267 cmd: |
268 set -e;
269 find /srv/salt/reclass/classes/cluster/ -type f -exec sed -i 's/system.keepalived.*/service.keepalived.cluster.single/g' {} +
270 find /srv/salt/reclass/classes/system/ -type f -exec sed -i 's/system.keepalived.*/service.keepalived.cluster.single/g' {} +
271
272 node_name: {{ HOSTNAME_CFG01 }}
273 retry: {count: 1, delay: 5}
274 skip_fail: false
275
276- description: "[EXPERIMENTAL] Create environment model for virtual environment"
277 cmd: |
278 set -e;
279 ln -s '/tmp/environment/environment_template/{{ '{# interfaces #}' }}' '/tmp/environment/environment_template/{{ '{{ cookiecutter._env_name }}' }}/';
280 ln -s '/tmp/environment/environment_template/{{ '{# roles #}' }}' '/tmp/environment/environment_template/{{ '{{ cookiecutter._env_name }}' }}/';
281 reclass-tools render --template-dir /tmp/environment/environment_template/ \
282 --output-dir /srv/salt/reclass/classes/environment/ \
283 --context {{ ENVIRONMENT_CONTEXT_PATH }} \
284 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
285 node_name: {{ HOSTNAME_CFG01 }}
286 retry: {count: 1, delay: 5}
287 skip_fail: false
288
289- description: Modify generated model and reclass-system if necessary
290 cmd: |
291 set -e;
292 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
293 pushd /srv/salt/reclass/classes/system/
294 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
295 popd
296 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' -%}
297 pushd /srv/salt/reclass/classes/system/
298 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
299 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD
300 {%- endfor %}
301 popd
302 {%- endif %}
303
304 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
305 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
306
307 {%- if IS_CONTRAIL_LAB %}
308 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
309 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
310 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
311 {%- endif %}
312
313 node_name: {{ HOSTNAME_CFG01 }}
314 retry: {count: 1, delay: 1}
315 skip_fail: false
316{%- endmacro %}
317
318
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300319{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
320{#######################################################}
321- description: Configure reclass
322 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300323 set -e;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300324 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
325 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
326 FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg};
327 which wget > /dev/null || (apt-get update; apt-get install -y wget);
328 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
329 wget -O - "${FORMULA_GPG}" | apt-key add -;
330 apt-get clean; apt-get update;
331 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
332 declare -a formula_services=({{ FORMULA_SERVICES }});
333 echo -e "\nInstalling all required salt formulas\n";
334 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
335 for formula_service in "${formula_services[@]}"; do
336 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
337 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
338 done;
339 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
340 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
341 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
342
343 cat << 'EOF' >> /etc/reclass/reclass-config.yml
344 storage_type: yaml_fs
345 pretty_print: True
346 output: yaml
347 inventory_base_uri: /srv/salt/reclass
348 EOF
349 node_name: {{ HOSTNAME_CFG01 }}
350 retry: {count: 1, delay: 1}
351 skip_fail: false
352
353- description: "*Workaround* remove all cfg01 nodes except {{ HOSTNAME_CFG01 }} to not depend on other clusters in 'reclass --top'"
354 cmd: |
355 # Remove all other nodes except {{ HOSTNAME_CFG01 }} to not rely on them for 'reclass --top'
356 find /srv/salt/reclass/nodes/ -type f -not -name {{ HOSTNAME_CFG01 }}.yml -delete
357 node_name: {{ HOSTNAME_CFG01 }}
358 retry: {count: 1, delay: 5}
359 skip_fail: false
360
361- description: Configure salt adoptors on cfg01
362 cmd: |
363 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
364 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
365 node_name: {{ HOSTNAME_CFG01 }}
366 retry: {count: 1, delay: 1}
367 skip_fail: false
368
369- description: Show reclass-salt --top for cfg01 node
370 cmd: reclass-salt --top
371 node_name: {{ HOSTNAME_CFG01 }}
372 retry: {count: 1, delay: 5}
373 skip_fail: false
374
375- description: Restart salt-master service
376 cmd: systemctl restart salt-master;
377 node_name: {{ HOSTNAME_CFG01 }}
378 retry: {count: 1, delay: 5}
379 skip_fail: false
380{%- endmacro %}
381
382
383{%- macro MACRO_INSTALL_SALT_MINIONS() %}
384{#######################################}
385{% for ssh in config.underlay.ssh %}
386- description: Configure salt-minion on {{ ssh['node_name'] }}
387 cmd: |
388 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
389 cat << "EOF" >> /etc/salt/minion.d/minion.conf
390 id: {{ ssh['node_name'] }}
391 master: {{ config.salt.salt_master_host }}
392 EOF
393 eatmydata apt-get install -y salt-minion;
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300394 service salt-minion restart; # For case if salt-minion was already installed
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300395 node_name: {{ ssh['node_name'] }}
396 retry: {count: 1, delay: 1}
397 skip_fail: false
398{% endfor %}
399
400
401- description: Accept salt keys from all the nodes
402 cmd: salt-key -A -y
403 node_name: {{ HOSTNAME_CFG01 }}
404 retry: {count: 1, delay: 5}
405 skip_fail: true
406{%- endmacro %}
407
408
409{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
410{##################################################}
411
412{# Prepare salt services and nodes settings #}
413
414- description: Run 'linux' formula on cfg01
415 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
416 node_name: {{ HOSTNAME_CFG01 }}
417 retry: {count: 3, delay: 5}
418 skip_fail: false
419
420- description: Run 'openssh' formula on cfg01
421 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300422 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300423 salt --hard-crash --state-output=mixed --state-verbose=False
424 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300425 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300426 node_name: {{ HOSTNAME_CFG01 }}
427 retry: {count: 3, delay: 5}
428 skip_fail: false
429
430- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
431 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
432 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
433 node_name: {{ HOSTNAME_CFG01 }}
434 retry: {count: 1, delay: 1}
435 skip_fail: false
436
437- description: Run 'salt.master' formula on cfg01
438 cmd: timeout 120 salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
439 node_name: {{ HOSTNAME_CFG01 }}
440 retry: {count: 2, delay: 5}
441 skip_fail: false
442
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400443{%- if SALT_FORMULAS_REFS != '' %}
444- description: Replace needed formulas to desired version
445 cmd: |
446 set -e;
447 {%- for formula in SALT_FORMULAS_REFS.split(' ') %}
448 {% set formula_name = formula.0 %}
449 {% set formula_ref = formula.1 %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300450 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400451 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
452 pushd {{ formula_dir }} &&
453 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
454 git checkout FETCH_HEAD &&
455 popd &&
456 if [ -d "{{ formula_dir }}" ]; then
457 echo "Going to replace packaged formula {{ formula_name }}" &&
458 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
459 ln -v -s \"{{ formula_dir }}/{{ formula_name }}\" \"/usr/share/salt-formulas/env/{{ formula_name }}\" &&
460 ln -v -s \"{{ formula_dir }}/metadata/service/\" \"/usr/share/salt-formulas/reclass/service/{{ formula_name }}\";
461 else
462 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
463 fi
464 {%- endfor %}
465 node_name: {{ HOSTNAME_CFG01 }}
466 retry: {count: 1, delay: 10}
467 skip_fail: false
468{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300469
470- description: Refresh pillars on salt-master minion
471 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
472 node_name: {{ HOSTNAME_CFG01 }}
473 retry: {count: 1, delay: 5}
474 skip_fail: false
475
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300476- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300477 cmd: reclass-salt --top
478 node_name: {{ HOSTNAME_CFG01 }}
479 retry: {count: 1, delay: 5}
480 skip_fail: false
481
482- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300483 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 +0300484 node_name: {{ HOSTNAME_CFG01 }}
485 retry: {count: 1, delay: 5}
486 skip_fail: false
487
488- description: Configure linux on master
489 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
490 node_name: {{ HOSTNAME_CFG01 }}
491 retry: {count: 1, delay: 5}
492 skip_fail: false
493
494- description: Configure salt.minion on master
495 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
496 -C 'I@salt:master' state.sls salt.minion && sleep 10
497 node_name: {{ HOSTNAME_CFG01 }}
498 retry: {count: 3, delay: 10}
499 skip_fail: false
500
501- description: Run state 'salt' on master (for salt.api, etc)
502 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
503 -C 'I@salt:master' state.sls salt
504 node_name: {{ HOSTNAME_CFG01 }}
505 retry: {count: 3, delay: 10}
506 skip_fail: false
507{%- endmacro %}
508
509{%- macro MACRO_GENERATE_INVENTORY() %}
510{#####################################}
511- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
512 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
513 -C 'I@salt:master' state.sls reclass
514 node_name: {{ HOSTNAME_CFG01 }}
515 retry: {count: 1, delay: 5}
516 skip_fail: false
517
518- description: Refresh pillars on all minions
519 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
520 node_name: {{ HOSTNAME_CFG01 }}
521 retry: {count: 1, delay: 5}
522 skip_fail: false
523
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300524- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300525 cmd: |
526 set -e
527 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
528 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
529 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300530 node_name: {{ HOSTNAME_CFG01 }}
531 retry: {count: 1, delay: 5}
532 skip_fail: false
533
534- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300535 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300536 node_name: {{ HOSTNAME_CFG01 }}
537 retry: {count: 1, delay: 5}
538 skip_fail: false
539{%- endmacro %}
540
541
542{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
543{########################################}
544# Bootstrap all nodes
545- description: Configure linux on other nodes
546 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
547 node_name: {{ HOSTNAME_CFG01 }}
548 retry: {count: 5, delay: 10}
549 skip_fail: false
550
551- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300552 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 +0300553 salt --hard-crash --state-output=mixed --state-verbose=False
554 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
555 yes/' /etc/ssh/sshd_config && service ssh reload"
556 node_name: {{ HOSTNAME_CFG01 }}
557 retry: {count: 1, delay: 5}
558 skip_fail: false
559
560- description: Configure salt.minion on other nodes
561 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion &&
562 sleep 10
563 node_name: {{ HOSTNAME_CFG01 }}
564 retry: {count: 3, delay: 15}
565 skip_fail: false
566
567- description: Check salt minion versions on slaves
568 cmd: salt '*' test.version
569 node_name: {{ HOSTNAME_CFG01 }}
570 retry: {count: 3, delay: 15}
571 skip_fail: false
572
573- description: Check salt top states on nodes
574 cmd: salt '*' state.show_top
575 node_name: {{ HOSTNAME_CFG01 }}
576 retry: {count: 1, delay: 5}
577 skip_fail: false
578
579- description: Configure ntp and rsyslog on nodes
580 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
581 node_name: {{ HOSTNAME_CFG01 }}
582 retry: {count: 1, delay: 10}
583 skip_fail: false
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200584{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300585
586
587{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
588{#########################################}
589
590- description: '*Workaround 1/2* of the bug PROD-9576 to get bond0-connectivity *without* rebooting nodes'
591 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False cmd.run
592 "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 +0300593 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 +0300594 cp -f linux/network/interface.sls /srv/salt/env/prd/linux/network/;
595 cp -f linux/map.jinja /srv/salt/env/prd/linux/;"
596 node_name: {{ HOSTNAME_CFG01 }}
597 retry: {count: 1, delay: 5}
598 skip_fail: false
599
600- description: '*Workaround: Load bonding module before call state.linux'
601 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
602 node_name: {{ HOSTNAME_CFG01 }}
603 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +0300604 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300605
606- description: '*Workaround* install bridge-utils before running linux formula'
607 # The formula removes default route and then tries to install the package, fails.
608 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
609 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
610 node_name: {{ HOSTNAME_CFG01 }}
611 retry: {count: 1, delay: 5}
612 skip_fail: false
613
614{%- endmacro %}