blob: 87d56eebcb9ba104f7c734c59410f39e6c235f7f [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','') %}
sgudz4d816eb2017-11-13 11:58:05 +020011{% set COOKIECUTTER_REF_CHANGE = os_env('COOKIECUTTER_REF_CHANGE','') %}
sgudzcced67d2017-10-11 15:56:09 +030012{% set ENVIRONMENT_TEMPLATE_REF_CHANGE = os_env('ENVIRONMENT_TEMPLATE_REF_CHANGE','') %}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020013
Dennis Dmitriev492813e2017-08-09 15:08:58 +030014{% set REPOSITORY_SUITE = os_env('REPOSITORY_SUITE', 'testing') %}
15
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020016{# Address pools for reclass cluster model are taken in the following order:
17 # 1. environment variables,
18 # 2. config.underlay.address_pools based on fuel-devops address pools
19 # (see generated '.ini' file after underlay is created),
20 # 3. defaults #}
21{% set address_pools = config.underlay.address_pools %}
22{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
23{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
24{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
25{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
26{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
27{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
28{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
29{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
30
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040031{# Format for formula replacement:
32 # space separated string:
33 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
34
35{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
36{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.net/salt-formulas') %}
37
Dennis Dmitriev492813e2017-08-09 15:08:58 +030038
39{%- macro MACRO_INSTALL_SALT_MASTER() %}
40{######################################}
41- description: Installing salt master on cfg01
42 cmd: eatmydata apt-get install -y reclass git salt-master
43 node_name: {{ HOSTNAME_CFG01 }}
44 retry: {count: 1, delay: 1}
45 skip_fail: false
46
47- description: Configure salt-master on cfg01
48 cmd: |
49 cat << 'EOF' >> /etc/salt/master.d/master.conf
50 file_roots:
51 base:
52 - /usr/share/salt-formulas/env
53 pillar_opts: False
54 open_mode: True
55 reclass: &reclass
56 storage_type: yaml_fs
57 inventory_base_uri: /srv/salt/reclass
58 ext_pillar:
59 - reclass: *reclass
60 master_tops:
61 reclass: *reclass
62 EOF
63 node_name: {{ HOSTNAME_CFG01 }}
64 retry: {count: 1, delay: 1}
65 skip_fail: false
66
67- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +030068 cmd: |
69 set -e;
70 touch /root/.git_trusted_certs.pem;
71 for server in github.com; do \
72 openssl s_client -showcerts -connect $server:443 </dev/null \
73 | openssl x509 -outform PEM \
Dennis Dmitriev492813e2017-08-09 15:08:58 +030074 >> /root/.git_trusted_certs.pem;
75 done;
76 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
77 HOME=/root git config --global user.email "tcp-qa@example.com";
78 HOME=/root git config --global user.name "TCP QA";
79 node_name: {{ HOSTNAME_CFG01 }}
80 retry: {count: 1, delay: 1}
81 skip_fail: false
82{%- endmacro %}
83
Dennis Dmitriev492813e2017-08-09 15:08:58 +030084{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false) %}
85{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +030086{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
87
Dennis Dmitriev492813e2017-08-09 15:08:58 +030088- description: Clone reclass models with submodules
89 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +030090 set -e;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020091 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Tatyana Leontovich44162732017-08-28 12:36:00 +030092 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 +020093 pushd /srv/salt/reclass && \
94 {%- if SALT_MODELS_REF_CHANGE != '' %}
95 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
96 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD && \
97 {%- endfor %}
98 {%- elif SALT_MODELS_COMMIT != 'master' %}
99 git checkout {{ SALT_MODELS_COMMIT }} && \
100 {%- endif %}
101 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
102 pushd classes/system/ && \
103 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
104 popd && \
sgudz4d816eb2017-11-13 11:58:05 +0200105 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300106 pushd classes/system/ && \
107 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
108 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD && \
109 {%- endfor %}
110 popd && \
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200111 {%- else %}
112 git submodule update --init --recursive && \
113 {%- endif %}
114 popd;
115 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrieva14f5562017-10-02 12:59:53 +0300116 rm -rf /srv/salt/reclass/nodes/ # For backward compatibility. New cfg node will be regenerated here
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300117 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200118
119 # Replace firstly to an intermediate value to avoid intersection between
120 # already replaced and replacing networks.
121 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
122 # 192.168.10 -> 10.16.0 (generated network for admin)
123 # 10.16.0 -> <external network>
124 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300125 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
126 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
127 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
128 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} +
129 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200130
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300131 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
132 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
133 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} +
134 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 +0200135
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300136 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 +0200137
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300138 {%- if IS_CONTRAIL_LAB %}
139 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300140 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 +0300141 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 +0300142 {%- endif %}
143
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200144 # Disable checkouting the model from remote repository
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300145 cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml
146 classes:
147 - cluster.{{ LAB_CONFIG_NAME }}.infra.config
148 parameters:
149 _param:
150 linux_system_codename: xenial
151 reclass_data_revision: master
152 linux:
153 system:
154 name: cfg01
155 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200156 reclass:
157 storage:
158 data_source:
159 engine: local
160 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300161
162 # Show the changes to the console
163 cd /srv/salt/reclass/; git diff
164 node_name: {{ HOSTNAME_CFG01 }}
165 retry: {count: 1, delay: 1}
166 skip_fail: false
167{%- endmacro %}
168
169
sgudz8c888ec2017-10-02 15:29:23 +0300170{%- macro MACRO_GENERATE_COOKIECUTTER_MODEL(IS_CONTRAIL_LAB=false, CONTROL_VLAN=None, TENANT_VLAN=None) %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300171{###################################################################}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300172{%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300173- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to {{ HOSTNAME_CFG01 }}"
174 upload:
175 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
176 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300177 remote_path: /tmp/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300178 node_name: {{ HOSTNAME_CFG01 }}
179
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300180- description: Create cluster model from cookiecutter templates
181 cmd: |
182 set -e;
183 pip install cookiecutter
184 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates /tmp/cookiecutter-templates
sgudz4d816eb2017-11-13 11:58:05 +0200185
186 {%- if COOKIECUTTER_REF_CHANGE != '' %}
187 pushd /tmp/cookiecutter-templates
188 git fetch https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
189 popd
190 {%- endif %}
191
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300192 mkdir -p /srv/salt/reclass/classes/cluster/
193 mkdir -p /srv/salt/reclass/classes/system/
194 mkdir -p /srv/salt/reclass/classes/service/
Dennis Dmitrieva14f5562017-10-02 12:59:53 +0300195 rm -rf /srv/salt/reclass/nodes/ # For backward compatibility. New cfg node will be regenerated here
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300196 mkdir -p /srv/salt/reclass/nodes/_generated
197
198 # Override some context parameters
199 sed -i 's/cluster_name:.*/cluster_name: {{ LAB_CONFIG_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
200 sed -i 's/cluster_domain:.*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300201 {%- if CONTROL_VLAN %}
202 sed -i 's/control_vlan:.*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
203 {%- endif %}
204 {%- if TENANT_VLAN %}
205 sed -i 's/tenant_vlan:.*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
206 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300207
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300208 # Replace firstly to an intermediate value to avoid intersection between
209 # already replaced and replacing networks.
210 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
211 # 192.168.10 -> 10.16.0 (generated network for admin)
212 # 10.16.0 -> <external network>
213 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
214 sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
215 sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
216 sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
217 sed -i 's/172\.17\.16\./==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
218
Dennis Dmitriev39e64bd2017-09-21 22:37:40 +0300219 sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
220 sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
221 sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
222 sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300223
224 for i in $(ls /tmp/cookiecutter-templates/cluster_product/); do
225 python /tmp/cookiecutter-templates/generate.py \
226 --template /tmp/cookiecutter-templates/cluster_product/$i \
227 --config-file {{ CLUSTER_CONTEXT_PATH }} \
228 --output-dir /srv/salt/reclass/classes/cluster/;
229 done
230
231 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/
232
233 # Create the cfg01 node and disable checkouting the model from remote repository
234 cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml
235 classes:
236 - system.openssh.server.team.all
237 - cluster.{{ LAB_CONFIG_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300238 EOF
239
240 node_name: {{ HOSTNAME_CFG01 }}
241 retry: {count: 1, delay: 1}
242 skip_fail: false
243
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300244- description: Modify generated model and reclass-system if necessary
245 cmd: |
246 set -e;
247 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
248 pushd /srv/salt/reclass/classes/system/
249 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
250 popd
sgudz4d816eb2017-11-13 11:58:05 +0200251 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300252 pushd /srv/salt/reclass/classes/system/
253 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
254 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD
255 {%- endfor %}
256 popd
257 {%- endif %}
258
259 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
260 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
261
262 {%- if IS_CONTRAIL_LAB %}
263 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
264 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
265 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
266 {%- endif %}
267
268 node_name: {{ HOSTNAME_CFG01 }}
269 retry: {count: 1, delay: 1}
270 skip_fail: false
271{%- endmacro %}
272
273
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300274{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
275{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300276
sgudzcced67d2017-10-11 15:56:09 +0300277- description: "[EXPERIMENTAL] Clone 'environment-template' repository to {{ HOSTNAME_CFG01 }}."
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300278 cmd: |
279 set -e;
280 mkdir -p /tmp/environment/;
281 export GIT_SSL_NO_VERIFY=true; git clone https://github.com/Mirantis/environment-template /tmp/environment/environment_template
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300282 node_name: {{ HOSTNAME_CFG01 }}
283 skip_fail: false
284
sgudzcced67d2017-10-11 15:56:09 +0300285{%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
286- description: Fetch changes for environment templates
287 cmd: |
288 set -e;
289 pushd /tmp/environment/environment_template &&
290 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
291 git checkout FETCH_HEAD &&
292 popd
293 node_name: {{ HOSTNAME_CFG01 }}
294 skip_fail: false
295{%- endif %}
296
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300297{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300298- description: "[EXPERIMENTAL] Upload environment inventory to {{ HOSTNAME_CFG01 }}"
299 upload:
300 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
301 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
302 remote_path: /tmp/environment/
303 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300304{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300305
306- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
307 cmd: |
308 set -e;
309 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
310 pip install git+https://github.com/dis-xcom/reclass-tools;
311 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
312 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
313 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
314
315 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
316 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml --merge ;
317 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}' /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml --merge ;
318 fi;
319
320 node_name: {{ HOSTNAME_CFG01 }}
321 retry: {count: 1, delay: 5}
322 skip_fail: false
323
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200324- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300325 cmd: |
326 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200327 find /srv/salt/reclass/classes/{system,cluster}/ -name '*.yml' -type f -exec sed -ri '/^ keepalived:/{:1;N;/\n instance:/!b1 {N; /\n [[:graph:]]+:/ { s/\n instance:\n [[:graph:]]+:/\n instance:\n VIP:/ } } }' {} +
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300328
329 node_name: {{ HOSTNAME_CFG01 }}
330 retry: {count: 1, delay: 5}
331 skip_fail: false
332
333- description: "[EXPERIMENTAL] Create environment model for virtual environment"
334 cmd: |
335 set -e;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300336 reclass-tools render --template-dir /tmp/environment/environment_template/ \
337 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitrievd55a8562017-09-28 22:12:09 +0300338 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /tmp/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300339 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
340 node_name: {{ HOSTNAME_CFG01 }}
341 retry: {count: 1, delay: 5}
342 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300343
344- description: Modify generated model and reclass-system
345 cmd: |
346 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
347 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
348 node_name: {{ HOSTNAME_CFG01 }}
349 retry: {count: 1, delay: 1}
350 skip_fail: false
351
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300352{%- endmacro %}
353
354
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300355{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
356{#######################################################}
357- description: Configure reclass
358 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300359 set -e;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300360 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
361 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
362 FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg};
363 which wget > /dev/null || (apt-get update; apt-get install -y wget);
364 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
365 wget -O - "${FORMULA_GPG}" | apt-key add -;
366 apt-get clean; apt-get update;
367 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
368 declare -a formula_services=({{ FORMULA_SERVICES }});
369 echo -e "\nInstalling all required salt formulas\n";
370 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
371 for formula_service in "${formula_services[@]}"; do
372 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
373 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
374 done;
375 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
376 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
377 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
378
379 cat << 'EOF' >> /etc/reclass/reclass-config.yml
380 storage_type: yaml_fs
381 pretty_print: True
382 output: yaml
383 inventory_base_uri: /srv/salt/reclass
384 EOF
385 node_name: {{ HOSTNAME_CFG01 }}
386 retry: {count: 1, delay: 1}
387 skip_fail: false
388
389- description: "*Workaround* remove all cfg01 nodes except {{ HOSTNAME_CFG01 }} to not depend on other clusters in 'reclass --top'"
390 cmd: |
391 # Remove all other nodes except {{ HOSTNAME_CFG01 }} to not rely on them for 'reclass --top'
392 find /srv/salt/reclass/nodes/ -type f -not -name {{ HOSTNAME_CFG01 }}.yml -delete
393 node_name: {{ HOSTNAME_CFG01 }}
394 retry: {count: 1, delay: 5}
395 skip_fail: false
396
397- description: Configure salt adoptors on cfg01
398 cmd: |
399 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
400 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
401 node_name: {{ HOSTNAME_CFG01 }}
402 retry: {count: 1, delay: 1}
403 skip_fail: false
404
405- description: Show reclass-salt --top for cfg01 node
406 cmd: reclass-salt --top
407 node_name: {{ HOSTNAME_CFG01 }}
408 retry: {count: 1, delay: 5}
409 skip_fail: false
410
411- description: Restart salt-master service
412 cmd: systemctl restart salt-master;
413 node_name: {{ HOSTNAME_CFG01 }}
414 retry: {count: 1, delay: 5}
415 skip_fail: false
416{%- endmacro %}
417
418
419{%- macro MACRO_INSTALL_SALT_MINIONS() %}
420{#######################################}
421{% for ssh in config.underlay.ssh %}
422- description: Configure salt-minion on {{ ssh['node_name'] }}
423 cmd: |
424 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
425 cat << "EOF" >> /etc/salt/minion.d/minion.conf
426 id: {{ ssh['node_name'] }}
427 master: {{ config.salt.salt_master_host }}
428 EOF
429 eatmydata apt-get install -y salt-minion;
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300430 service salt-minion restart; # For case if salt-minion was already installed
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300431 node_name: {{ ssh['node_name'] }}
432 retry: {count: 1, delay: 1}
433 skip_fail: false
434{% endfor %}
435
436
437- description: Accept salt keys from all the nodes
438 cmd: salt-key -A -y
439 node_name: {{ HOSTNAME_CFG01 }}
440 retry: {count: 1, delay: 5}
441 skip_fail: true
442{%- endmacro %}
443
444
445{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
446{##################################################}
447
448{# Prepare salt services and nodes settings #}
449
450- description: Run 'linux' formula on cfg01
451 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
452 node_name: {{ HOSTNAME_CFG01 }}
453 retry: {count: 3, delay: 5}
454 skip_fail: false
455
456- description: Run 'openssh' formula on cfg01
457 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300458 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300459 salt --hard-crash --state-output=mixed --state-verbose=False
460 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300461 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300462 node_name: {{ HOSTNAME_CFG01 }}
463 retry: {count: 3, delay: 5}
464 skip_fail: false
465
466- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
467 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
468 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
469 node_name: {{ HOSTNAME_CFG01 }}
470 retry: {count: 1, delay: 1}
471 skip_fail: false
472
473- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300474 cmd: timeout 600 salt-call -l info --hard-crash --state-output=mixed --state-verbose=False state.sls salt.master;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300475 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300476 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300477 skip_fail: false
478
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400479{%- if SALT_FORMULAS_REFS != '' %}
480- description: Replace needed formulas to desired version
481 cmd: |
482 set -e;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400483 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
484 {% set formula = formula_set.split(':') %}
485 {% set formula_name = formula[0] %}
486 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300487 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400488 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
489 pushd {{ formula_dir }} &&
490 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
491 git checkout FETCH_HEAD &&
492 popd &&
493 if [ -d "{{ formula_dir }}" ]; then
494 echo "Going to replace packaged formula {{ formula_name }}" &&
495 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400496 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
497 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400498 else
499 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
500 fi
501 {%- endfor %}
502 node_name: {{ HOSTNAME_CFG01 }}
503 retry: {count: 1, delay: 10}
504 skip_fail: false
505{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300506
507- description: Refresh pillars on salt-master minion
508 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
509 node_name: {{ HOSTNAME_CFG01 }}
510 retry: {count: 1, delay: 5}
511 skip_fail: false
512
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300513- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300514 cmd: reclass-salt --top
515 node_name: {{ HOSTNAME_CFG01 }}
516 retry: {count: 1, delay: 5}
517 skip_fail: false
518
519- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300520 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 +0300521 node_name: {{ HOSTNAME_CFG01 }}
522 retry: {count: 1, delay: 5}
523 skip_fail: false
524
525- description: Configure linux on master
526 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
527 node_name: {{ HOSTNAME_CFG01 }}
528 retry: {count: 1, delay: 5}
529 skip_fail: false
530
531- description: Configure salt.minion on master
532 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
533 -C 'I@salt:master' state.sls salt.minion && sleep 10
534 node_name: {{ HOSTNAME_CFG01 }}
535 retry: {count: 3, delay: 10}
536 skip_fail: false
537
538- description: Run state 'salt' on master (for salt.api, etc)
539 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
540 -C 'I@salt:master' state.sls salt
541 node_name: {{ HOSTNAME_CFG01 }}
542 retry: {count: 3, delay: 10}
543 skip_fail: false
544{%- endmacro %}
545
546{%- macro MACRO_GENERATE_INVENTORY() %}
547{#####################################}
548- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
549 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
550 -C 'I@salt:master' state.sls reclass
551 node_name: {{ HOSTNAME_CFG01 }}
552 retry: {count: 1, delay: 5}
553 skip_fail: false
554
555- description: Refresh pillars on all minions
556 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
557 node_name: {{ HOSTNAME_CFG01 }}
558 retry: {count: 1, delay: 5}
559 skip_fail: false
560
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300561- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300562 cmd: |
563 set -e
564 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
565 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
566 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300567 node_name: {{ HOSTNAME_CFG01 }}
568 retry: {count: 1, delay: 5}
569 skip_fail: false
570
571- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300572 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300573 node_name: {{ HOSTNAME_CFG01 }}
574 retry: {count: 1, delay: 5}
575 skip_fail: false
576{%- endmacro %}
577
578
579{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
580{########################################}
581# Bootstrap all nodes
582- description: Configure linux on other nodes
583 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
584 node_name: {{ HOSTNAME_CFG01 }}
585 retry: {count: 5, delay: 10}
586 skip_fail: false
587
588- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300589 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 +0300590 salt --hard-crash --state-output=mixed --state-verbose=False
591 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
592 yes/' /etc/ssh/sshd_config && service ssh reload"
593 node_name: {{ HOSTNAME_CFG01 }}
594 retry: {count: 1, delay: 5}
595 skip_fail: false
596
597- description: Configure salt.minion on other nodes
598 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion &&
599 sleep 10
600 node_name: {{ HOSTNAME_CFG01 }}
601 retry: {count: 3, delay: 15}
602 skip_fail: false
603
604- description: Check salt minion versions on slaves
Tatyanka Leontovich3b1f40e2017-11-14 20:45:23 -0400605 cmd: salt '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300606 node_name: {{ HOSTNAME_CFG01 }}
607 retry: {count: 3, delay: 15}
608 skip_fail: false
609
610- description: Check salt top states on nodes
Tatyanka Leontovich3b1f40e2017-11-14 20:45:23 -0400611 cmd: salt '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300612 node_name: {{ HOSTNAME_CFG01 }}
Tatyanka Leontovich3b1f40e2017-11-14 20:45:23 -0400613 retry: {count: 1, delay: 5}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300614 skip_fail: false
615
616- description: Configure ntp and rsyslog on nodes
617 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
618 node_name: {{ HOSTNAME_CFG01 }}
619 retry: {count: 1, delay: 10}
620 skip_fail: false
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200621{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300622
623
624{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
625{#########################################}
626
Oleksii Butenkof72f9d12017-10-18 13:10:04 +0300627#- description: '*Workaround 1/2* of the bug PROD-9576 to get bond0-connectivity *without* rebooting nodes'
628# cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False cmd.run
629# "mkdir -p /tmp/PROD-9576; cd /tmp/PROD-9576; git clone https://gerrit.mcp.mirantis.net/salt-formulas/linux; cd linux;
630# git fetch https://gerrit.mcp.mirantis.net/salt-formulas/linux refs/changes/54/2354/16 && git checkout FETCH_HEAD;
631# cp -f linux/network/interface.sls /srv/salt/env/prd/linux/network/;
632# cp -f linux/map.jinja /srv/salt/env/prd/linux/;"
633# node_name: {{ HOSTNAME_CFG01 }}
634# retry: {count: 1, delay: 5}
635# skip_fail: false
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300636
637- description: '*Workaround: Load bonding module before call state.linux'
638 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
639 node_name: {{ HOSTNAME_CFG01 }}
640 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +0300641 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300642
643- description: '*Workaround* install bridge-utils before running linux formula'
644 # The formula removes default route and then tries to install the package, fails.
645 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
646 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
647 node_name: {{ HOSTNAME_CFG01 }}
648 retry: {count: 1, delay: 5}
649 skip_fail: false
650
651{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400652
653{%- macro ADJUST_K8S_OPTS() %}
654{#########################################}
655
656- description: Set k8s deploy parameters
657 cmd: |
658 {% for k8s_opt, value in config.k8s_deploy.items() %}
659 {% if value|string() %}
660 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
661 {% endif %}
662 {% endfor %}
663 node_name: {{ HOSTNAME_CFG01 }}
664 retry: {count: 1, delay: 1}
665 skip_fail: false
666
667{%- endmacro %}