blob: 1cb8a8cbe22916ebeb8d7c8941058629e2fb0656 [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
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040038# Needed for using different models in different templates
39{% set CLUSTER_NAME = os_env('DOMAIN_NAME', LAB_CONFIG_NAME) %}
40
Dennis Dmitriev492813e2017-08-09 15:08:58 +030041
42{%- macro MACRO_INSTALL_SALT_MASTER() %}
43{######################################}
44- description: Installing salt master on cfg01
45 cmd: eatmydata apt-get install -y reclass git salt-master
46 node_name: {{ HOSTNAME_CFG01 }}
47 retry: {count: 1, delay: 1}
48 skip_fail: false
49
50- description: Configure salt-master on cfg01
51 cmd: |
52 cat << 'EOF' >> /etc/salt/master.d/master.conf
53 file_roots:
54 base:
55 - /usr/share/salt-formulas/env
56 pillar_opts: False
57 open_mode: True
58 reclass: &reclass
59 storage_type: yaml_fs
60 inventory_base_uri: /srv/salt/reclass
61 ext_pillar:
62 - reclass: *reclass
63 master_tops:
64 reclass: *reclass
65 EOF
66 node_name: {{ HOSTNAME_CFG01 }}
67 retry: {count: 1, delay: 1}
68 skip_fail: false
69
70- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +030071 cmd: |
72 set -e;
73 touch /root/.git_trusted_certs.pem;
74 for server in github.com; do \
75 openssl s_client -showcerts -connect $server:443 </dev/null \
76 | openssl x509 -outform PEM \
Dennis Dmitriev492813e2017-08-09 15:08:58 +030077 >> /root/.git_trusted_certs.pem;
78 done;
79 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
80 HOME=/root git config --global user.email "tcp-qa@example.com";
81 HOME=/root git config --global user.name "TCP QA";
82 node_name: {{ HOSTNAME_CFG01 }}
83 retry: {count: 1, delay: 1}
84 skip_fail: false
85{%- endmacro %}
86
Dennis Dmitriev492813e2017-08-09 15:08:58 +030087{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false) %}
88{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +030089{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
90
Dennis Dmitriev492813e2017-08-09 15:08:58 +030091- description: Clone reclass models with submodules
92 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +030093 set -e;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020094 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Tatyana Leontovich44162732017-08-28 12:36:00 +030095 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 +020096 pushd /srv/salt/reclass && \
97 {%- if SALT_MODELS_REF_CHANGE != '' %}
98 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
99 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD && \
100 {%- endfor %}
101 {%- elif SALT_MODELS_COMMIT != 'master' %}
102 git checkout {{ SALT_MODELS_COMMIT }} && \
103 {%- endif %}
104 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
105 pushd classes/system/ && \
106 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
107 popd && \
sgudz4d816eb2017-11-13 11:58:05 +0200108 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300109 pushd classes/system/ && \
110 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
111 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD && \
112 {%- endfor %}
113 popd && \
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200114 {%- else %}
115 git submodule update --init --recursive && \
116 {%- endif %}
117 popd;
118 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrieva14f5562017-10-02 12:59:53 +0300119 rm -rf /srv/salt/reclass/nodes/ # For backward compatibility. New cfg node will be regenerated here
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300120 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200121
122 # Replace firstly to an intermediate value to avoid intersection between
123 # already replaced and replacing networks.
124 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
125 # 192.168.10 -> 10.16.0 (generated network for admin)
126 # 10.16.0 -> <external network>
127 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300128 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
129 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
130 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
131 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} +
132 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0\./==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/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
135 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
136 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} +
137 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 +0200138
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300139 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 +0200140
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300141 {%- if IS_CONTRAIL_LAB %}
142 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300143 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 +0300144 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 +0300145 {%- endif %}
146
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200147 # Disable checkouting the model from remote repository
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300148 cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml
149 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400150 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300151 parameters:
152 _param:
153 linux_system_codename: xenial
154 reclass_data_revision: master
155 linux:
156 system:
157 name: cfg01
158 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200159 reclass:
160 storage:
161 data_source:
162 engine: local
163 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300164
165 # Show the changes to the console
166 cd /srv/salt/reclass/; git diff
167 node_name: {{ HOSTNAME_CFG01 }}
168 retry: {count: 1, delay: 1}
169 skip_fail: false
170{%- endmacro %}
171
172
sgudz8c888ec2017-10-02 15:29:23 +0300173{%- macro MACRO_GENERATE_COOKIECUTTER_MODEL(IS_CONTRAIL_LAB=false, CONTROL_VLAN=None, TENANT_VLAN=None) %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300174{###################################################################}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300175{%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300176- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to {{ HOSTNAME_CFG01 }}"
177 upload:
178 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
179 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300180 remote_path: /tmp/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300181 node_name: {{ HOSTNAME_CFG01 }}
182
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300183- description: Create cluster model from cookiecutter templates
184 cmd: |
185 set -e;
186 pip install cookiecutter
187 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 +0200188
189 {%- if COOKIECUTTER_REF_CHANGE != '' %}
190 pushd /tmp/cookiecutter-templates
191 git fetch https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
192 popd
193 {%- endif %}
194
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300195 mkdir -p /srv/salt/reclass/classes/cluster/
196 mkdir -p /srv/salt/reclass/classes/system/
197 mkdir -p /srv/salt/reclass/classes/service/
Dennis Dmitrieva14f5562017-10-02 12:59:53 +0300198 rm -rf /srv/salt/reclass/nodes/ # For backward compatibility. New cfg node will be regenerated here
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300199 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 }}
sgudz8c888ec2017-10-02 15:29:23 +0300204 {%- if CONTROL_VLAN %}
205 sed -i 's/control_vlan:.*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
206 {%- endif %}
207 {%- if TENANT_VLAN %}
208 sed -i 's/tenant_vlan:.*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
209 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300210
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300211 # 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
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300241 EOF
242
243 node_name: {{ HOSTNAME_CFG01 }}
244 retry: {count: 1, delay: 1}
245 skip_fail: false
246
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300247- description: Modify generated model and reclass-system if necessary
248 cmd: |
249 set -e;
250 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
251 pushd /srv/salt/reclass/classes/system/
252 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
253 popd
sgudz4d816eb2017-11-13 11:58:05 +0200254 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300255 pushd /srv/salt/reclass/classes/system/
256 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
257 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD
258 {%- endfor %}
259 popd
260 {%- endif %}
261
262 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
263 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
264
265 {%- if IS_CONTRAIL_LAB %}
266 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
267 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
268 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
269 {%- endif %}
270
271 node_name: {{ HOSTNAME_CFG01 }}
272 retry: {count: 1, delay: 1}
273 skip_fail: false
274{%- endmacro %}
275
276
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300277{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
278{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300279
sgudzcced67d2017-10-11 15:56:09 +0300280- description: "[EXPERIMENTAL] Clone 'environment-template' repository to {{ HOSTNAME_CFG01 }}."
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300281 cmd: |
282 set -e;
283 mkdir -p /tmp/environment/;
284 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 +0300285 node_name: {{ HOSTNAME_CFG01 }}
286 skip_fail: false
287
sgudzcced67d2017-10-11 15:56:09 +0300288{%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
289- description: Fetch changes for environment templates
290 cmd: |
291 set -e;
292 pushd /tmp/environment/environment_template &&
293 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
294 git checkout FETCH_HEAD &&
295 popd
296 node_name: {{ HOSTNAME_CFG01 }}
297 skip_fail: false
298{%- endif %}
299
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300300{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300301- description: "[EXPERIMENTAL] Upload environment inventory to {{ HOSTNAME_CFG01 }}"
302 upload:
303 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
304 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
305 remote_path: /tmp/environment/
306 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300307{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300308
309- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
310 cmd: |
311 set -e;
312 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
313 pip install git+https://github.com/dis-xcom/reclass-tools;
314 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
315 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
316 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
317
318 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
319 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml --merge ;
320 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}' /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml --merge ;
321 fi;
322
323 node_name: {{ HOSTNAME_CFG01 }}
324 retry: {count: 1, delay: 5}
325 skip_fail: false
326
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200327- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300328 cmd: |
329 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200330 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 +0300331
332 node_name: {{ HOSTNAME_CFG01 }}
333 retry: {count: 1, delay: 5}
334 skip_fail: false
335
336- description: "[EXPERIMENTAL] Create environment model for virtual environment"
337 cmd: |
338 set -e;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300339 reclass-tools render --template-dir /tmp/environment/environment_template/ \
340 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitrievd55a8562017-09-28 22:12:09 +0300341 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /tmp/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300342 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
343 node_name: {{ HOSTNAME_CFG01 }}
344 retry: {count: 1, delay: 5}
345 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300346
347- description: Modify generated model and reclass-system
348 cmd: |
349 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
350 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
351 node_name: {{ HOSTNAME_CFG01 }}
352 retry: {count: 1, delay: 1}
353 skip_fail: false
354
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300355{%- endmacro %}
356
357
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300358{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
359{#######################################################}
360- description: Configure reclass
361 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300362 set -e;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300363 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
364 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
365 FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg};
366 which wget > /dev/null || (apt-get update; apt-get install -y wget);
367 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
368 wget -O - "${FORMULA_GPG}" | apt-key add -;
369 apt-get clean; apt-get update;
370 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
371 declare -a formula_services=({{ FORMULA_SERVICES }});
372 echo -e "\nInstalling all required salt formulas\n";
373 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
374 for formula_service in "${formula_services[@]}"; do
375 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
376 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
377 done;
378 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
379 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
380 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
381
382 cat << 'EOF' >> /etc/reclass/reclass-config.yml
383 storage_type: yaml_fs
384 pretty_print: True
385 output: yaml
386 inventory_base_uri: /srv/salt/reclass
387 EOF
388 node_name: {{ HOSTNAME_CFG01 }}
389 retry: {count: 1, delay: 1}
390 skip_fail: false
391
392- description: "*Workaround* remove all cfg01 nodes except {{ HOSTNAME_CFG01 }} to not depend on other clusters in 'reclass --top'"
393 cmd: |
394 # Remove all other nodes except {{ HOSTNAME_CFG01 }} to not rely on them for 'reclass --top'
395 find /srv/salt/reclass/nodes/ -type f -not -name {{ HOSTNAME_CFG01 }}.yml -delete
396 node_name: {{ HOSTNAME_CFG01 }}
397 retry: {count: 1, delay: 5}
398 skip_fail: false
399
400- description: Configure salt adoptors on cfg01
401 cmd: |
402 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
403 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
404 node_name: {{ HOSTNAME_CFG01 }}
405 retry: {count: 1, delay: 1}
406 skip_fail: false
407
408- description: Show reclass-salt --top for cfg01 node
409 cmd: reclass-salt --top
410 node_name: {{ HOSTNAME_CFG01 }}
411 retry: {count: 1, delay: 5}
412 skip_fail: false
413
414- description: Restart salt-master service
415 cmd: systemctl restart salt-master;
416 node_name: {{ HOSTNAME_CFG01 }}
417 retry: {count: 1, delay: 5}
418 skip_fail: false
419{%- endmacro %}
420
421
422{%- macro MACRO_INSTALL_SALT_MINIONS() %}
423{#######################################}
424{% for ssh in config.underlay.ssh %}
425- description: Configure salt-minion on {{ ssh['node_name'] }}
426 cmd: |
427 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
428 cat << "EOF" >> /etc/salt/minion.d/minion.conf
429 id: {{ ssh['node_name'] }}
430 master: {{ config.salt.salt_master_host }}
431 EOF
432 eatmydata apt-get install -y salt-minion;
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300433 service salt-minion restart; # For case if salt-minion was already installed
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300434 node_name: {{ ssh['node_name'] }}
435 retry: {count: 1, delay: 1}
436 skip_fail: false
437{% endfor %}
438
439
440- description: Accept salt keys from all the nodes
441 cmd: salt-key -A -y
442 node_name: {{ HOSTNAME_CFG01 }}
443 retry: {count: 1, delay: 5}
444 skip_fail: true
445{%- endmacro %}
446
447
448{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
449{##################################################}
450
451{# Prepare salt services and nodes settings #}
452
453- description: Run 'linux' formula on cfg01
454 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
455 node_name: {{ HOSTNAME_CFG01 }}
456 retry: {count: 3, delay: 5}
457 skip_fail: false
458
459- description: Run 'openssh' formula on cfg01
460 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300461 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300462 salt --hard-crash --state-output=mixed --state-verbose=False
463 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300464 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300465 node_name: {{ HOSTNAME_CFG01 }}
466 retry: {count: 3, delay: 5}
467 skip_fail: false
468
469- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
470 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
471 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
472 node_name: {{ HOSTNAME_CFG01 }}
473 retry: {count: 1, delay: 1}
474 skip_fail: false
475
476- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300477 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 +0300478 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300479 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300480 skip_fail: false
481
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400482{%- if SALT_FORMULAS_REFS != '' %}
483- description: Replace needed formulas to desired version
484 cmd: |
485 set -e;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400486 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
487 {% set formula = formula_set.split(':') %}
488 {% set formula_name = formula[0] %}
489 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300490 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400491 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
492 pushd {{ formula_dir }} &&
493 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
494 git checkout FETCH_HEAD &&
495 popd &&
496 if [ -d "{{ formula_dir }}" ]; then
497 echo "Going to replace packaged formula {{ formula_name }}" &&
498 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400499 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
500 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400501 else
502 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
503 fi
504 {%- endfor %}
505 node_name: {{ HOSTNAME_CFG01 }}
506 retry: {count: 1, delay: 10}
507 skip_fail: false
508{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300509
510- description: Refresh pillars on salt-master minion
511 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
512 node_name: {{ HOSTNAME_CFG01 }}
513 retry: {count: 1, delay: 5}
514 skip_fail: false
515
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300516- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300517 cmd: reclass-salt --top
518 node_name: {{ HOSTNAME_CFG01 }}
519 retry: {count: 1, delay: 5}
520 skip_fail: false
521
522- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300523 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 +0300524 node_name: {{ HOSTNAME_CFG01 }}
525 retry: {count: 1, delay: 5}
526 skip_fail: false
527
528- description: Configure linux on master
529 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
530 node_name: {{ HOSTNAME_CFG01 }}
531 retry: {count: 1, delay: 5}
532 skip_fail: false
533
534- description: Configure salt.minion on master
535 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
536 -C 'I@salt:master' state.sls salt.minion && sleep 10
537 node_name: {{ HOSTNAME_CFG01 }}
538 retry: {count: 3, delay: 10}
539 skip_fail: false
540
541- description: Run state 'salt' on master (for salt.api, etc)
542 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
543 -C 'I@salt:master' state.sls salt
544 node_name: {{ HOSTNAME_CFG01 }}
545 retry: {count: 3, delay: 10}
546 skip_fail: false
547{%- endmacro %}
548
549{%- macro MACRO_GENERATE_INVENTORY() %}
550{#####################################}
551- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
552 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
553 -C 'I@salt:master' state.sls reclass
554 node_name: {{ HOSTNAME_CFG01 }}
555 retry: {count: 1, delay: 5}
556 skip_fail: false
557
558- description: Refresh pillars on all minions
559 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
560 node_name: {{ HOSTNAME_CFG01 }}
561 retry: {count: 1, delay: 5}
562 skip_fail: false
563
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300564- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300565 cmd: |
566 set -e
567 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
568 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
569 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300570 node_name: {{ HOSTNAME_CFG01 }}
571 retry: {count: 1, delay: 5}
572 skip_fail: false
573
574- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300575 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300576 node_name: {{ HOSTNAME_CFG01 }}
577 retry: {count: 1, delay: 5}
578 skip_fail: false
579{%- endmacro %}
580
581
582{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
583{########################################}
584# Bootstrap all nodes
585- description: Configure linux on other nodes
586 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
587 node_name: {{ HOSTNAME_CFG01 }}
588 retry: {count: 5, delay: 10}
589 skip_fail: false
590
591- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300592 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 +0300593 salt --hard-crash --state-output=mixed --state-verbose=False
594 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
595 yes/' /etc/ssh/sshd_config && service ssh reload"
596 node_name: {{ HOSTNAME_CFG01 }}
597 retry: {count: 1, delay: 5}
598 skip_fail: false
599
600- description: Configure salt.minion on other nodes
601 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion &&
602 sleep 10
603 node_name: {{ HOSTNAME_CFG01 }}
604 retry: {count: 3, delay: 15}
605 skip_fail: false
606
607- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400608 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300609 node_name: {{ HOSTNAME_CFG01 }}
610 retry: {count: 3, delay: 15}
611 skip_fail: false
612
613- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400614 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300615 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400616 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300617 skip_fail: false
618
619- description: Configure ntp and rsyslog on nodes
620 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
621 node_name: {{ HOSTNAME_CFG01 }}
622 retry: {count: 1, delay: 10}
623 skip_fail: false
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200624{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300625
626
627{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
628{#########################################}
629
Oleksii Butenkof72f9d12017-10-18 13:10:04 +0300630#- description: '*Workaround 1/2* of the bug PROD-9576 to get bond0-connectivity *without* rebooting nodes'
631# cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False cmd.run
632# "mkdir -p /tmp/PROD-9576; cd /tmp/PROD-9576; git clone https://gerrit.mcp.mirantis.net/salt-formulas/linux; cd linux;
633# git fetch https://gerrit.mcp.mirantis.net/salt-formulas/linux refs/changes/54/2354/16 && git checkout FETCH_HEAD;
634# cp -f linux/network/interface.sls /srv/salt/env/prd/linux/network/;
635# cp -f linux/map.jinja /srv/salt/env/prd/linux/;"
636# node_name: {{ HOSTNAME_CFG01 }}
637# retry: {count: 1, delay: 5}
638# skip_fail: false
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300639
640- description: '*Workaround: Load bonding module before call state.linux'
641 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
642 node_name: {{ HOSTNAME_CFG01 }}
643 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +0300644 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300645
646- description: '*Workaround* install bridge-utils before running linux formula'
647 # The formula removes default route and then tries to install the package, fails.
648 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
649 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
650 node_name: {{ HOSTNAME_CFG01 }}
651 retry: {count: 1, delay: 5}
652 skip_fail: false
653
654{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400655
656{%- macro ADJUST_K8S_OPTS() %}
657{#########################################}
658
659- description: Set k8s deploy parameters
660 cmd: |
661 {% for k8s_opt, value in config.k8s_deploy.items() %}
662 {% if value|string() %}
663 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
664 {% endif %}
665 {% endfor %}
666 node_name: {{ HOSTNAME_CFG01 }}
667 retry: {count: 1, delay: 1}
668 skip_fail: false
669
670{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400671
672{%- macro REGISTER_COMPUTE_NODES() %}
673{#########################################}
674
675{% for ssh in config.underlay.ssh %}
676{% if ssh["node_name"].startswith("cmp") %}
677{% set node_hostname = ssh["node_name"].split('.')[0] %}
678- description: Register compute {{ ssh['node_name'] }}
679 cmd: |
680 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
681 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
682 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400683 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400684 export config_host={{ config.salt.salt_master_host }}
685 export node_domain={{ DOMAIN_NAME }}
686 export nodes_os="xenial"
687 export node_hostname={{ node_hostname }}
688 set -xe
689 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
690 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
691 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
692 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
693
694 # Add wrapper to apt-get to avoid race conditions
695 # with cron jobs running 'unattended-upgrades' script
696 aptget_wrapper() {
697 local apt_wrapper_timeout=300
698 local start_time=$(date '+%s')
699 local fin_time=$((start_time + apt_wrapper_timeout))
700 while true; do
701 if (( "$(date '+%s')" > fin_time )); then
702 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
703 fi
704 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
705 echo "Waiting while another apt/dpkg process releases locks ..."
706 sleep 30
707 continue
708 else
709 apt-get $@
710 break
711 fi
712 done
713 }
714
715 # Set default salt version
716 if [ -z "$saltversion" ]; then
717 saltversion="2016.3"
718 fi
719 echo "Using Salt version $saltversion"
720
721 echo "Preparing base OS ..."
722
723 case "$node_os" in
724 trusty)
725 # workaround for old cloud-init only configuring the first iface
726 iface_config_dir="/etc/network/interfaces"
727 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
728
729 for iface in $ifaces; do
730 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
731 done
732
733 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
734
735 # SUGGESTED UPDATE:
736 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
737 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
738 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
739 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
740 #install_salt_minion_pkg
741
742 # DEPRECATED:
743 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
744 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
745
746 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
747 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
748
749 aptget_wrapper clean
750 aptget_wrapper update
751 aptget_wrapper install -y salt-common
752 aptget_wrapper install -y salt-minion
753 ;;
754 xenial)
755
756 # workaround for new cloud-init setting all interfaces statically
757 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
758
759 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
760
761 # SUGGESTED UPDATE:
762 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
763 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
764 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
765 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
766 #install_salt_minion_pkg
767
768 # DEPRECATED:
769 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
770 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
771
772 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
773 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
774
775 aptget_wrapper clean
776 aptget_wrapper update
777 aptget_wrapper install -y salt-minion
778 ;;
779 rhel|centos|centos7|centos7|rhel6|rhel7)
780 yum install -y git
781 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
782 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
783 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
784 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
785 install_salt_minion_pkg
786 ;;
787 *)
788 msg="OS '$node_os' is not supported."
789 esac
790
791 echo "Configuring Salt minion ..."
792 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
793 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
794
795 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
796
797 sleep 1
798
799 echo "Classifying node ..."
800 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
801 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
802 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
803 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
804 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
805 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
806
807 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
808 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
809 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
810 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
811 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
812
813 if [ "$node_network05_iface" != "" ]; then
814 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
815 fi
816
817 # find more parameters (every env starting param_)
818 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
819 if [ "$more_params" != "" ]; then
820 echo "Additional params: $more_params"
821 more_params=", $more_params"
822 fi
823
824 salt-call event.send "reclass/minion/classify" "{\"node_master_ip\": \"$config_host\", \"node_os\": \"${os_codename}\", \"node_deploy_ip\": \"${node_network01_ip}\", \"node_deploy_iface\": \"${node_network01_iface}\", \"node_control_ip\": \"${node_network02_ip}\", \"node_control_iface\": \"${node_network02_iface}\", \"node_tenant_ip\": \"${node_network03_ip}\", \"node_tenant_iface\": \"${node_network03_iface}\", \"node_external_ip\": \"${node_network04_ip}\", \"node_external_iface\": \"${node_network04_iface}\", \"node_baremetal_ip\": \"${node_network05_ip}\", \"node_baremetal_iface\": \"${node_network05_iface}\", \"node_baremetal_hwaddress\": \"${node_network05_hwaddress}\", \"node_domain\": \"$node_domain\", \"node_cluster\": \"$cluster_name\", \"node_hostname\": \"$node_hostname\"${more_params}}"
825
826 sleep 5
827
828 salt-call saltutil.sync_all
829 salt-call mine.flush
830 salt-call mine.update
831 node_name: {{ ssh['node_name'] }}
832 retry: {count: 1, delay: 1}
833 skip_fail: false
834{%- endif %}
835{%- endfor %}
836
837- description: Refresh pillars on all minions
838 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
839 node_name: {{ HOSTNAME_CFG01 }}
840 retry: {count: 1, delay: 5}
841 skip_fail: false
842
843- description: Sync all salt resources
844 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
845 node_name: {{ HOSTNAME_CFG01 }}
846 retry: {count: 1, delay: 5}
847 skip_fail: false
848
849{%- endmacro %}