blob: b14f868533ddd1dacbdfd235d6dd65db9f813cc9 [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') %}
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020015{% set FORMULA_REPOSITORY = os_env('FORMULA_REPOSITORY', 'deb [arch=amd64] http://apt.mirantis.com/xenial ' + REPOSITORY_SUITE + ' salt') %}
16{% set FORMULA_GPG = os_env('FORMULA_GPG', 'http://apt.mirantis.com/public.gpg') %}
17{% set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb http://repo.saltstack.local.test/apt/ubuntu/16.04/amd64/2016.3 xenial main") %}
18{% set SALT_GPG = os_env('SALT_GPG', 'http://repo.saltstack.local.test/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub') %}
19{% set UBUNTU_REPOSITORY = os_env('UBUNTU_REPOSITORY', "deb http://archive.ubuntu.com/ubuntu/ xenial main universe restricted") %}
20{% set UBUNTU_UPDATES_REPOSITORY = os_env('UBUNTU_UPDATES_REPOSITORY', "deb http://archive.ubuntu.com/ubuntu/ xenial-updates main universe restricted") %}
21{% set UBUNTU_SECURITY_REPOSITORY = os_env('UBUNTU_SECURITY_REPOSITORY', "deb http://archive.ubuntu.com/ubuntu/ xenial-security main universe restricted") %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +030022
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020023{# Address pools for reclass cluster model are taken in the following order:
24 # 1. environment variables,
25 # 2. config.underlay.address_pools based on fuel-devops address pools
26 # (see generated '.ini' file after underlay is created),
27 # 3. defaults #}
28{% set address_pools = config.underlay.address_pools %}
29{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
30{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
31{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
32{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
33{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
34{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
35{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
36{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
37
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040038{# Format for formula replacement:
39 # space separated string:
40 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
41
42{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
43{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.net/salt-formulas') %}
44
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040045# Needed for using different models in different templates
46{% set CLUSTER_NAME = os_env('DOMAIN_NAME', LAB_CONFIG_NAME) %}
47
Dennis Dmitriev492813e2017-08-09 15:08:58 +030048
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020049{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
50{#####################################################}
51
52- description: 'Configure key on nodes and install packages'
53 cmd: |
54 rm -rf trusted* ;
55 rm -rf /etc/apt/sources.list ;
56 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
57 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
58 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
59 wget -O - "{{ SALT_GPG }}" | apt-key add -;
60 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
61 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
62 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
63 eatmydata apt-get clean && apt-get update;
64 node_name: {{ NODE_NAME }}
65 retry: {count: 1, delay: 5}
66 skip_fail: false
67
68{%- endmacro %}
69
70
Dennis Dmitriev492813e2017-08-09 15:08:58 +030071{%- macro MACRO_INSTALL_SALT_MASTER() %}
72{######################################}
73- description: Installing salt master on cfg01
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020074 cmd: eatmydata apt-get install -y --allow-unauthenticated reclass git salt-master
Dennis Dmitriev492813e2017-08-09 15:08:58 +030075 node_name: {{ HOSTNAME_CFG01 }}
76 retry: {count: 1, delay: 1}
77 skip_fail: false
78
79- description: Configure salt-master on cfg01
80 cmd: |
81 cat << 'EOF' >> /etc/salt/master.d/master.conf
82 file_roots:
83 base:
84 - /usr/share/salt-formulas/env
85 pillar_opts: False
86 open_mode: True
87 reclass: &reclass
88 storage_type: yaml_fs
89 inventory_base_uri: /srv/salt/reclass
90 ext_pillar:
91 - reclass: *reclass
92 master_tops:
93 reclass: *reclass
94 EOF
95 node_name: {{ HOSTNAME_CFG01 }}
96 retry: {count: 1, delay: 1}
97 skip_fail: false
98
99- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300100 cmd: |
101 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200102 #touch /root/.git_trusted_certs.pem;
103 #for server in github.com; do \
104 # openssl s_client -showcerts -connect $server:443 </dev/null \
105 # | openssl x509 -outform PEM \
106 # >> /root/.git_trusted_certs.pem;
107 #done;
108 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
109 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
110 HOME=/root git config --global user.name "MCP Integration QA";
111 HOME=/root git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300112 node_name: {{ HOSTNAME_CFG01 }}
113 retry: {count: 1, delay: 1}
114 skip_fail: false
115{%- endmacro %}
116
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300117{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false) %}
118{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300119{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
120
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300121- description: Clone reclass models with submodules
122 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300123 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200124 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Tatyana Leontovich44162732017-08-28 12:36:00 +0300125 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 +0200126 pushd /srv/salt/reclass && \
127 {%- if SALT_MODELS_REF_CHANGE != '' %}
128 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
129 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD && \
130 {%- endfor %}
131 {%- elif SALT_MODELS_COMMIT != 'master' %}
132 git checkout {{ SALT_MODELS_COMMIT }} && \
133 {%- endif %}
134 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
135 pushd classes/system/ && \
136 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
137 popd && \
sgudz4d816eb2017-11-13 11:58:05 +0200138 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300139 pushd classes/system/ && \
140 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
141 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD && \
142 {%- endfor %}
143 popd && \
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200144 {%- else %}
145 git submodule update --init --recursive && \
146 {%- endif %}
147 popd;
148 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrieva14f5562017-10-02 12:59:53 +0300149 rm -rf /srv/salt/reclass/nodes/ # For backward compatibility. New cfg node will be regenerated here
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300150 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200151
152 # Replace firstly to an intermediate value to avoid intersection between
153 # already replaced and replacing networks.
154 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
155 # 192.168.10 -> 10.16.0 (generated network for admin)
156 # 10.16.0 -> <external network>
157 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300158 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
159 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
160 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
161 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} +
162 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200163
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300164 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
165 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
166 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} +
167 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 +0200168
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300169 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 +0200170
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300171 {%- if IS_CONTRAIL_LAB %}
172 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300173 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 +0300174 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 +0300175 {%- endif %}
176
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200177 # Disable checkouting the model from remote repository
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300178 cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml
179 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400180 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300181 parameters:
182 _param:
183 linux_system_codename: xenial
184 reclass_data_revision: master
185 linux:
186 system:
187 name: cfg01
188 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200189 reclass:
190 storage:
191 data_source:
192 engine: local
193 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300194
195 # Show the changes to the console
196 cd /srv/salt/reclass/; git diff
197 node_name: {{ HOSTNAME_CFG01 }}
198 retry: {count: 1, delay: 1}
199 skip_fail: false
200{%- endmacro %}
201
202
sgudz8c888ec2017-10-02 15:29:23 +0300203{%- macro MACRO_GENERATE_COOKIECUTTER_MODEL(IS_CONTRAIL_LAB=false, CONTROL_VLAN=None, TENANT_VLAN=None) %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300204{###################################################################}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300205{%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300206- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to {{ HOSTNAME_CFG01 }}"
207 upload:
208 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
209 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300210 remote_path: /tmp/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300211 node_name: {{ HOSTNAME_CFG01 }}
212
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300213- description: Create cluster model from cookiecutter templates
214 cmd: |
215 set -e;
216 pip install cookiecutter
217 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 +0200218
219 {%- if COOKIECUTTER_REF_CHANGE != '' %}
220 pushd /tmp/cookiecutter-templates
221 git fetch https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
222 popd
223 {%- endif %}
224
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300225 mkdir -p /srv/salt/reclass/classes/cluster/
226 mkdir -p /srv/salt/reclass/classes/system/
227 mkdir -p /srv/salt/reclass/classes/service/
Dennis Dmitrieva14f5562017-10-02 12:59:53 +0300228 rm -rf /srv/salt/reclass/nodes/ # For backward compatibility. New cfg node will be regenerated here
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300229 mkdir -p /srv/salt/reclass/nodes/_generated
230
231 # Override some context parameters
232 sed -i 's/cluster_name:.*/cluster_name: {{ LAB_CONFIG_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
233 sed -i 's/cluster_domain:.*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300234 {%- if CONTROL_VLAN %}
235 sed -i 's/control_vlan:.*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
236 {%- endif %}
237 {%- if TENANT_VLAN %}
238 sed -i 's/tenant_vlan:.*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
239 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300240
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300241 # Replace firstly to an intermediate value to avoid intersection between
242 # already replaced and replacing networks.
243 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
244 # 192.168.10 -> 10.16.0 (generated network for admin)
245 # 10.16.0 -> <external network>
246 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
247 sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
248 sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
249 sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
250 sed -i 's/172\.17\.16\./==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
251
Dennis Dmitriev39e64bd2017-09-21 22:37:40 +0300252 sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
253 sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
254 sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
255 sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300256
257 for i in $(ls /tmp/cookiecutter-templates/cluster_product/); do
258 python /tmp/cookiecutter-templates/generate.py \
259 --template /tmp/cookiecutter-templates/cluster_product/$i \
260 --config-file {{ CLUSTER_CONTEXT_PATH }} \
261 --output-dir /srv/salt/reclass/classes/cluster/;
262 done
263
264 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/
265
266 # Create the cfg01 node and disable checkouting the model from remote repository
267 cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml
268 classes:
269 - system.openssh.server.team.all
270 - cluster.{{ LAB_CONFIG_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300271 EOF
272
273 node_name: {{ HOSTNAME_CFG01 }}
274 retry: {count: 1, delay: 1}
275 skip_fail: false
276
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300277- description: Modify generated model and reclass-system if necessary
278 cmd: |
279 set -e;
280 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
281 pushd /srv/salt/reclass/classes/system/
282 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
283 popd
sgudz4d816eb2017-11-13 11:58:05 +0200284 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300285 pushd /srv/salt/reclass/classes/system/
286 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
287 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD
288 {%- endfor %}
289 popd
290 {%- endif %}
291
292 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
293 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
294
295 {%- if IS_CONTRAIL_LAB %}
296 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
297 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
298 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
299 {%- endif %}
300
301 node_name: {{ HOSTNAME_CFG01 }}
302 retry: {count: 1, delay: 1}
303 skip_fail: false
304{%- endmacro %}
305
306
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300307{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
308{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300309
sgudzcced67d2017-10-11 15:56:09 +0300310- description: "[EXPERIMENTAL] Clone 'environment-template' repository to {{ HOSTNAME_CFG01 }}."
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300311 cmd: |
312 set -e;
313 mkdir -p /tmp/environment/;
314 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 +0300315 node_name: {{ HOSTNAME_CFG01 }}
316 skip_fail: false
317
sgudzcced67d2017-10-11 15:56:09 +0300318{%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
319- description: Fetch changes for environment templates
320 cmd: |
321 set -e;
322 pushd /tmp/environment/environment_template &&
323 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
324 git checkout FETCH_HEAD &&
325 popd
326 node_name: {{ HOSTNAME_CFG01 }}
327 skip_fail: false
328{%- endif %}
329
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300330{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300331- description: "[EXPERIMENTAL] Upload environment inventory to {{ HOSTNAME_CFG01 }}"
332 upload:
333 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
334 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
335 remote_path: /tmp/environment/
336 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300337{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300338
339- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
340 cmd: |
341 set -e;
342 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
343 pip install git+https://github.com/dis-xcom/reclass-tools;
344 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
345 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
346 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
347
348 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
349 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml --merge ;
350 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}' /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml --merge ;
351 fi;
352
353 node_name: {{ HOSTNAME_CFG01 }}
354 retry: {count: 1, delay: 5}
355 skip_fail: false
356
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200357- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300358 cmd: |
359 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200360 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 +0300361
362 node_name: {{ HOSTNAME_CFG01 }}
363 retry: {count: 1, delay: 5}
364 skip_fail: false
365
366- description: "[EXPERIMENTAL] Create environment model for virtual environment"
367 cmd: |
368 set -e;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300369 reclass-tools render --template-dir /tmp/environment/environment_template/ \
370 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitrievd55a8562017-09-28 22:12:09 +0300371 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /tmp/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300372 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
373 node_name: {{ HOSTNAME_CFG01 }}
374 retry: {count: 1, delay: 5}
375 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300376
377- description: Modify generated model and reclass-system
378 cmd: |
379 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
380 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
381 node_name: {{ HOSTNAME_CFG01 }}
382 retry: {count: 1, delay: 1}
383 skip_fail: false
384
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300385{%- endmacro %}
386
387
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300388{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
389{#######################################################}
390- description: Configure reclass
391 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300392 set -e;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300393 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300394 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200395 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
396 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300397 apt-get clean; apt-get update;
398 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
399 declare -a formula_services=({{ FORMULA_SERVICES }});
400 echo -e "\nInstalling all required salt formulas\n";
401 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
402 for formula_service in "${formula_services[@]}"; do
403 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
404 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
405 done;
406 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
407 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
408 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
409
410 cat << 'EOF' >> /etc/reclass/reclass-config.yml
411 storage_type: yaml_fs
412 pretty_print: True
413 output: yaml
414 inventory_base_uri: /srv/salt/reclass
415 EOF
416 node_name: {{ HOSTNAME_CFG01 }}
417 retry: {count: 1, delay: 1}
418 skip_fail: false
419
420- description: "*Workaround* remove all cfg01 nodes except {{ HOSTNAME_CFG01 }} to not depend on other clusters in 'reclass --top'"
421 cmd: |
422 # Remove all other nodes except {{ HOSTNAME_CFG01 }} to not rely on them for 'reclass --top'
423 find /srv/salt/reclass/nodes/ -type f -not -name {{ HOSTNAME_CFG01 }}.yml -delete
424 node_name: {{ HOSTNAME_CFG01 }}
425 retry: {count: 1, delay: 5}
426 skip_fail: false
427
428- description: Configure salt adoptors on cfg01
429 cmd: |
430 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
431 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
432 node_name: {{ HOSTNAME_CFG01 }}
433 retry: {count: 1, delay: 1}
434 skip_fail: false
435
436- description: Show reclass-salt --top for cfg01 node
437 cmd: reclass-salt --top
438 node_name: {{ HOSTNAME_CFG01 }}
439 retry: {count: 1, delay: 5}
440 skip_fail: false
441
442- description: Restart salt-master service
443 cmd: systemctl restart salt-master;
444 node_name: {{ HOSTNAME_CFG01 }}
445 retry: {count: 1, delay: 5}
446 skip_fail: false
447{%- endmacro %}
448
449
450{%- macro MACRO_INSTALL_SALT_MINIONS() %}
451{#######################################}
452{% for ssh in config.underlay.ssh %}
453- description: Configure salt-minion on {{ ssh['node_name'] }}
454 cmd: |
455 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
456 cat << "EOF" >> /etc/salt/minion.d/minion.conf
457 id: {{ ssh['node_name'] }}
458 master: {{ config.salt.salt_master_host }}
459 EOF
460 eatmydata apt-get install -y salt-minion;
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300461 service salt-minion restart; # For case if salt-minion was already installed
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300462 node_name: {{ ssh['node_name'] }}
463 retry: {count: 1, delay: 1}
464 skip_fail: false
465{% endfor %}
466
467
468- description: Accept salt keys from all the nodes
469 cmd: salt-key -A -y
470 node_name: {{ HOSTNAME_CFG01 }}
471 retry: {count: 1, delay: 5}
472 skip_fail: true
473{%- endmacro %}
474
475
476{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
477{##################################################}
478
479{# Prepare salt services and nodes settings #}
480
481- description: Run 'linux' formula on cfg01
482 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
483 node_name: {{ HOSTNAME_CFG01 }}
484 retry: {count: 3, delay: 5}
485 skip_fail: false
486
487- description: Run 'openssh' formula on cfg01
488 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300489 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300490 salt --hard-crash --state-output=mixed --state-verbose=False
491 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300492 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300493 node_name: {{ HOSTNAME_CFG01 }}
494 retry: {count: 3, delay: 5}
495 skip_fail: false
496
497- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
498 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
499 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
500 node_name: {{ HOSTNAME_CFG01 }}
501 retry: {count: 1, delay: 1}
502 skip_fail: false
503
504- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300505 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 +0300506 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300507 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300508 skip_fail: false
509
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400510{%- if SALT_FORMULAS_REFS != '' %}
511- description: Replace needed formulas to desired version
512 cmd: |
513 set -e;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400514 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
515 {% set formula = formula_set.split(':') %}
516 {% set formula_name = formula[0] %}
517 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300518 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400519 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
520 pushd {{ formula_dir }} &&
521 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
522 git checkout FETCH_HEAD &&
523 popd &&
524 if [ -d "{{ formula_dir }}" ]; then
525 echo "Going to replace packaged formula {{ formula_name }}" &&
526 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400527 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
528 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400529 else
530 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
531 fi
532 {%- endfor %}
533 node_name: {{ HOSTNAME_CFG01 }}
534 retry: {count: 1, delay: 10}
535 skip_fail: false
536{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300537
538- description: Refresh pillars on salt-master minion
539 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
540 node_name: {{ HOSTNAME_CFG01 }}
541 retry: {count: 1, delay: 5}
542 skip_fail: false
543
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300544- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300545 cmd: reclass-salt --top
546 node_name: {{ HOSTNAME_CFG01 }}
547 retry: {count: 1, delay: 5}
548 skip_fail: false
549
550- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300551 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 +0300552 node_name: {{ HOSTNAME_CFG01 }}
553 retry: {count: 1, delay: 5}
554 skip_fail: false
555
556- description: Configure linux on master
557 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
558 node_name: {{ HOSTNAME_CFG01 }}
559 retry: {count: 1, delay: 5}
560 skip_fail: false
561
562- description: Configure salt.minion on master
563 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
564 -C 'I@salt:master' state.sls salt.minion && sleep 10
565 node_name: {{ HOSTNAME_CFG01 }}
566 retry: {count: 3, delay: 10}
567 skip_fail: false
568
569- description: Run state 'salt' on master (for salt.api, etc)
570 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
571 -C 'I@salt:master' state.sls salt
572 node_name: {{ HOSTNAME_CFG01 }}
573 retry: {count: 3, delay: 10}
574 skip_fail: false
575{%- endmacro %}
576
577{%- macro MACRO_GENERATE_INVENTORY() %}
578{#####################################}
579- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
580 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
581 -C 'I@salt:master' state.sls reclass
582 node_name: {{ HOSTNAME_CFG01 }}
583 retry: {count: 1, delay: 5}
584 skip_fail: false
585
586- description: Refresh pillars on all minions
587 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
588 node_name: {{ HOSTNAME_CFG01 }}
589 retry: {count: 1, delay: 5}
590 skip_fail: false
591
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300592- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300593 cmd: |
594 set -e
595 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
596 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
597 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300598 node_name: {{ HOSTNAME_CFG01 }}
599 retry: {count: 1, delay: 5}
600 skip_fail: false
601
602- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300603 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300604 node_name: {{ HOSTNAME_CFG01 }}
605 retry: {count: 1, delay: 5}
606 skip_fail: false
607{%- endmacro %}
608
609
610{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
611{########################################}
612# Bootstrap all nodes
613- description: Configure linux on other nodes
614 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
615 node_name: {{ HOSTNAME_CFG01 }}
616 retry: {count: 5, delay: 10}
617 skip_fail: false
618
619- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300620 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 +0300621 salt --hard-crash --state-output=mixed --state-verbose=False
622 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
623 yes/' /etc/ssh/sshd_config && service ssh reload"
624 node_name: {{ HOSTNAME_CFG01 }}
625 retry: {count: 1, delay: 5}
626 skip_fail: false
627
628- description: Configure salt.minion on other nodes
629 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion &&
630 sleep 10
631 node_name: {{ HOSTNAME_CFG01 }}
632 retry: {count: 3, delay: 15}
633 skip_fail: false
634
635- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400636 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300637 node_name: {{ HOSTNAME_CFG01 }}
638 retry: {count: 3, delay: 15}
639 skip_fail: false
640
641- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400642 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300643 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400644 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300645 skip_fail: false
646
647- description: Configure ntp and rsyslog on nodes
648 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
649 node_name: {{ HOSTNAME_CFG01 }}
650 retry: {count: 1, delay: 10}
651 skip_fail: false
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200652{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300653
654
655{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
656{#########################################}
657
Oleksii Butenkof72f9d12017-10-18 13:10:04 +0300658#- description: '*Workaround 1/2* of the bug PROD-9576 to get bond0-connectivity *without* rebooting nodes'
659# cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False cmd.run
660# "mkdir -p /tmp/PROD-9576; cd /tmp/PROD-9576; git clone https://gerrit.mcp.mirantis.net/salt-formulas/linux; cd linux;
661# git fetch https://gerrit.mcp.mirantis.net/salt-formulas/linux refs/changes/54/2354/16 && git checkout FETCH_HEAD;
662# cp -f linux/network/interface.sls /srv/salt/env/prd/linux/network/;
663# cp -f linux/map.jinja /srv/salt/env/prd/linux/;"
664# node_name: {{ HOSTNAME_CFG01 }}
665# retry: {count: 1, delay: 5}
666# skip_fail: false
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300667
668- description: '*Workaround: Load bonding module before call state.linux'
669 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
670 node_name: {{ HOSTNAME_CFG01 }}
671 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +0300672 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300673
674- description: '*Workaround* install bridge-utils before running linux formula'
675 # The formula removes default route and then tries to install the package, fails.
676 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
677 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
678 node_name: {{ HOSTNAME_CFG01 }}
679 retry: {count: 1, delay: 5}
680 skip_fail: false
681
682{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400683
684{%- macro ADJUST_K8S_OPTS() %}
685{#########################################}
686
687- description: Set k8s deploy parameters
688 cmd: |
689 {% for k8s_opt, value in config.k8s_deploy.items() %}
690 {% if value|string() %}
691 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
692 {% endif %}
693 {% endfor %}
694 node_name: {{ HOSTNAME_CFG01 }}
695 retry: {count: 1, delay: 1}
696 skip_fail: false
697
698{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400699
700{%- macro REGISTER_COMPUTE_NODES() %}
701{#########################################}
702
703{% for ssh in config.underlay.ssh %}
704{% if ssh["node_name"].startswith("cmp") %}
705{% set node_hostname = ssh["node_name"].split('.')[0] %}
706- description: Register compute {{ ssh['node_name'] }}
707 cmd: |
708 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
709 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
710 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400711 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400712 export config_host={{ config.salt.salt_master_host }}
713 export node_domain={{ DOMAIN_NAME }}
714 export nodes_os="xenial"
715 export node_hostname={{ node_hostname }}
716 set -xe
717 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
718 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
719 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
720 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
721
722 # Add wrapper to apt-get to avoid race conditions
723 # with cron jobs running 'unattended-upgrades' script
724 aptget_wrapper() {
725 local apt_wrapper_timeout=300
726 local start_time=$(date '+%s')
727 local fin_time=$((start_time + apt_wrapper_timeout))
728 while true; do
729 if (( "$(date '+%s')" > fin_time )); then
730 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
731 fi
732 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
733 echo "Waiting while another apt/dpkg process releases locks ..."
734 sleep 30
735 continue
736 else
737 apt-get $@
738 break
739 fi
740 done
741 }
742
743 # Set default salt version
744 if [ -z "$saltversion" ]; then
745 saltversion="2016.3"
746 fi
747 echo "Using Salt version $saltversion"
748
749 echo "Preparing base OS ..."
750
751 case "$node_os" in
752 trusty)
753 # workaround for old cloud-init only configuring the first iface
754 iface_config_dir="/etc/network/interfaces"
755 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
756
757 for iface in $ifaces; do
758 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
759 done
760
761 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
762
763 # SUGGESTED UPDATE:
764 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
765 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
766 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
767 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
768 #install_salt_minion_pkg
769
770 # DEPRECATED:
771 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
772 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
773
774 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
775 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
776
777 aptget_wrapper clean
778 aptget_wrapper update
779 aptget_wrapper install -y salt-common
780 aptget_wrapper install -y salt-minion
781 ;;
782 xenial)
783
784 # workaround for new cloud-init setting all interfaces statically
785 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
786
787 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
788
789 # SUGGESTED UPDATE:
790 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
791 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
792 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
793 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
794 #install_salt_minion_pkg
795
796 # DEPRECATED:
797 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
798 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
799
800 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
801 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
802
803 aptget_wrapper clean
804 aptget_wrapper update
805 aptget_wrapper install -y salt-minion
806 ;;
807 rhel|centos|centos7|centos7|rhel6|rhel7)
808 yum install -y git
809 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
810 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
811 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
812 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
813 install_salt_minion_pkg
814 ;;
815 *)
816 msg="OS '$node_os' is not supported."
817 esac
818
819 echo "Configuring Salt minion ..."
820 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
821 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
822
823 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
824
825 sleep 1
826
827 echo "Classifying node ..."
828 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
829 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
830 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
831 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
832 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
833 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
834
835 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
836 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
837 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
838 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
839 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
840
841 if [ "$node_network05_iface" != "" ]; then
842 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
843 fi
844
845 # find more parameters (every env starting param_)
846 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
847 if [ "$more_params" != "" ]; then
848 echo "Additional params: $more_params"
849 more_params=", $more_params"
850 fi
851
852 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}}"
853
854 sleep 5
855
856 salt-call saltutil.sync_all
857 salt-call mine.flush
858 salt-call mine.update
859 node_name: {{ ssh['node_name'] }}
860 retry: {count: 1, delay: 1}
861 skip_fail: false
862{%- endif %}
863{%- endfor %}
864
865- description: Refresh pillars on all minions
866 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
867 node_name: {{ HOSTNAME_CFG01 }}
868 retry: {count: 1, delay: 5}
869 skip_fail: false
870
871- description: Sync all salt resources
872 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
873 node_name: {{ HOSTNAME_CFG01 }}
874 retry: {count: 1, delay: 5}
875 skip_fail: false
876
877{%- endmacro %}