blob: 52ffd96916033a1ff8ccd3f971f27f746c9887b8 [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
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020046{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040047
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";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300111 node_name: {{ HOSTNAME_CFG01 }}
112 retry: {count: 1, delay: 1}
113 skip_fail: false
114{%- endmacro %}
115
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300116{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false) %}
117{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300118{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
119
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300120- description: Clone reclass models with submodules
121 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300122 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200123 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200124 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200125 export GIT_SSL_NO_VERIFY=true; git clone -b {{ SALT_MODELS_BRANCH }} {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
126 pushd /srv/salt/reclass;
127 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
128 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200129 {%- if SALT_MODELS_REF_CHANGE != '' %}
130 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200131 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200132 {%- endfor %}
133 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200134 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200135 {%- endif %}
136 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200137 pushd classes/system/;
138 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
139 popd;
sgudz4d816eb2017-11-13 11:58:05 +0200140 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300141 pushd classes/system/ && \
142 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200143 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300144 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200145 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200146 {%- else %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200147 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200148 {%- endif %}
149 popd;
150 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrieva14f5562017-10-02 12:59:53 +0300151 rm -rf /srv/salt/reclass/nodes/ # For backward compatibility. New cfg node will be regenerated here
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300152 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200153
154 # Replace firstly to an intermediate value to avoid intersection between
155 # already replaced and replacing networks.
156 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
157 # 192.168.10 -> 10.16.0 (generated network for admin)
158 # 10.16.0 -> <external network>
159 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300160 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
161 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
162 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
163 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} +
164 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200165
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300166 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
167 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
168 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} +
169 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 +0200170
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300171 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 +0200172
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300173 {%- if IS_CONTRAIL_LAB %}
174 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300175 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 +0300176 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 +0300177 {%- endif %}
178
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200179 # Override some context parameters
180 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
181 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
182 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
183
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200184 # Disable checkouting the model from remote repository
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300185 cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml
186 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400187 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300188 parameters:
189 _param:
190 linux_system_codename: xenial
191 reclass_data_revision: master
192 linux:
193 system:
194 name: cfg01
195 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200196 reclass:
197 storage:
198 data_source:
199 engine: local
200 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300201
202 # Show the changes to the console
203 cd /srv/salt/reclass/; git diff
204 node_name: {{ HOSTNAME_CFG01 }}
205 retry: {count: 1, delay: 1}
206 skip_fail: false
207{%- endmacro %}
208
209
sgudz160b7302017-12-22 17:01:10 +0200210{%- macro MACRO_GENERATE_COOKIECUTTER_MODEL(IS_CONTRAIL_LAB=false, CONTROL_VLAN=None, TENANT_VLAN=None, CLUSTER_PRODUCT_MODELS='') %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300211{###################################################################}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300212{%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300213- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to {{ HOSTNAME_CFG01 }}"
214 upload:
215 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
216 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300217 remote_path: /tmp/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300218 node_name: {{ HOSTNAME_CFG01 }}
219
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300220- description: Create cluster model from cookiecutter templates
221 cmd: |
222 set -e;
223 pip install cookiecutter
224 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 +0200225
226 {%- if COOKIECUTTER_REF_CHANGE != '' %}
227 pushd /tmp/cookiecutter-templates
228 git fetch https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
229 popd
230 {%- endif %}
231
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300232 mkdir -p /srv/salt/reclass/classes/cluster/
233 mkdir -p /srv/salt/reclass/classes/system/
234 mkdir -p /srv/salt/reclass/classes/service/
Dennis Dmitrieva14f5562017-10-02 12:59:53 +0300235 rm -rf /srv/salt/reclass/nodes/ # For backward compatibility. New cfg node will be regenerated here
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300236 mkdir -p /srv/salt/reclass/nodes/_generated
237
238 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200239 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
240 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300241 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200242 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300243 {%- endif %}
244 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200245 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300246 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300247
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300248 # Replace firstly to an intermediate value to avoid intersection between
249 # already replaced and replacing networks.
250 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
251 # 192.168.10 -> 10.16.0 (generated network for admin)
252 # 10.16.0 -> <external network>
253 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
254 sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
255 sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
256 sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
257 sed -i 's/172\.17\.16\./==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
258
Dennis Dmitriev39e64bd2017-09-21 22:37:40 +0300259 sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
260 sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
261 sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
262 sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300263
sgudz160b7302017-12-22 17:01:10 +0200264 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /tmp/cookiecutter-templates/cluster_product/)' %}
265 for item in {{ items }}; do
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300266 python /tmp/cookiecutter-templates/generate.py \
sgudz160b7302017-12-22 17:01:10 +0200267 --template /tmp/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300268 --config-file {{ CLUSTER_CONTEXT_PATH }} \
269 --output-dir /srv/salt/reclass/classes/cluster/;
270 done
271
272 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/
273
274 # Create the cfg01 node and disable checkouting the model from remote repository
275 cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml
276 classes:
277 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200278 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300279 EOF
280
281 node_name: {{ HOSTNAME_CFG01 }}
282 retry: {count: 1, delay: 1}
283 skip_fail: false
284
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300285- description: Modify generated model and reclass-system if necessary
286 cmd: |
287 set -e;
288 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
289 pushd /srv/salt/reclass/classes/system/
290 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
291 popd
sgudz4d816eb2017-11-13 11:58:05 +0200292 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300293 pushd /srv/salt/reclass/classes/system/
294 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
295 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD
296 {%- endfor %}
297 popd
298 {%- endif %}
299
300 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
301 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
302
303 {%- if IS_CONTRAIL_LAB %}
304 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
305 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
306 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
307 {%- endif %}
308
309 node_name: {{ HOSTNAME_CFG01 }}
310 retry: {count: 1, delay: 1}
311 skip_fail: false
312{%- endmacro %}
313
314
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300315{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
316{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300317
sgudzcced67d2017-10-11 15:56:09 +0300318- description: "[EXPERIMENTAL] Clone 'environment-template' repository to {{ HOSTNAME_CFG01 }}."
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300319 cmd: |
320 set -e;
321 mkdir -p /tmp/environment/;
322 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 +0300323 node_name: {{ HOSTNAME_CFG01 }}
324 skip_fail: false
325
sgudzcced67d2017-10-11 15:56:09 +0300326{%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
327- description: Fetch changes for environment templates
328 cmd: |
329 set -e;
330 pushd /tmp/environment/environment_template &&
331 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
332 git checkout FETCH_HEAD &&
333 popd
334 node_name: {{ HOSTNAME_CFG01 }}
335 skip_fail: false
336{%- endif %}
337
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300338{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300339- description: "[EXPERIMENTAL] Upload environment inventory to {{ HOSTNAME_CFG01 }}"
340 upload:
341 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
342 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
343 remote_path: /tmp/environment/
344 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300345{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300346
347- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
348 cmd: |
349 set -e;
350 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
351 pip install git+https://github.com/dis-xcom/reclass-tools;
352 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
353 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
354 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
355
356 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
357 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml --merge ;
358 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}' /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml --merge ;
359 fi;
360
361 node_name: {{ HOSTNAME_CFG01 }}
362 retry: {count: 1, delay: 5}
363 skip_fail: false
364
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200365- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300366 cmd: |
367 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200368 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 +0300369
370 node_name: {{ HOSTNAME_CFG01 }}
371 retry: {count: 1, delay: 5}
372 skip_fail: false
373
374- description: "[EXPERIMENTAL] Create environment model for virtual environment"
375 cmd: |
376 set -e;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300377 reclass-tools render --template-dir /tmp/environment/environment_template/ \
378 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitrievd55a8562017-09-28 22:12:09 +0300379 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /tmp/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300380 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
381 node_name: {{ HOSTNAME_CFG01 }}
382 retry: {count: 1, delay: 5}
383 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300384
385- description: Modify generated model and reclass-system
386 cmd: |
387 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
388 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
389 node_name: {{ HOSTNAME_CFG01 }}
390 retry: {count: 1, delay: 1}
391 skip_fail: false
392
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300393{%- endmacro %}
394
395
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300396{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
397{#######################################################}
398- description: Configure reclass
399 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300400 set -e;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300401 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300402 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200403 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
404 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300405 apt-get clean; apt-get update;
406 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
407 declare -a formula_services=({{ FORMULA_SERVICES }});
408 echo -e "\nInstalling all required salt formulas\n";
409 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
410 for formula_service in "${formula_services[@]}"; do
411 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
412 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
413 done;
414 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
415 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
416 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
417
418 cat << 'EOF' >> /etc/reclass/reclass-config.yml
419 storage_type: yaml_fs
420 pretty_print: True
421 output: yaml
422 inventory_base_uri: /srv/salt/reclass
423 EOF
424 node_name: {{ HOSTNAME_CFG01 }}
425 retry: {count: 1, delay: 1}
426 skip_fail: false
427
428- description: "*Workaround* remove all cfg01 nodes except {{ HOSTNAME_CFG01 }} to not depend on other clusters in 'reclass --top'"
429 cmd: |
430 # Remove all other nodes except {{ HOSTNAME_CFG01 }} to not rely on them for 'reclass --top'
431 find /srv/salt/reclass/nodes/ -type f -not -name {{ HOSTNAME_CFG01 }}.yml -delete
432 node_name: {{ HOSTNAME_CFG01 }}
433 retry: {count: 1, delay: 5}
434 skip_fail: false
435
436- description: Configure salt adoptors on cfg01
437 cmd: |
438 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
439 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
440 node_name: {{ HOSTNAME_CFG01 }}
441 retry: {count: 1, delay: 1}
442 skip_fail: false
443
444- description: Show reclass-salt --top for cfg01 node
445 cmd: reclass-salt --top
446 node_name: {{ HOSTNAME_CFG01 }}
447 retry: {count: 1, delay: 5}
448 skip_fail: false
449
450- description: Restart salt-master service
451 cmd: systemctl restart salt-master;
452 node_name: {{ HOSTNAME_CFG01 }}
453 retry: {count: 1, delay: 5}
454 skip_fail: false
455{%- endmacro %}
456
457
458{%- macro MACRO_INSTALL_SALT_MINIONS() %}
459{#######################################}
460{% for ssh in config.underlay.ssh %}
461- description: Configure salt-minion on {{ ssh['node_name'] }}
462 cmd: |
463 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
464 cat << "EOF" >> /etc/salt/minion.d/minion.conf
465 id: {{ ssh['node_name'] }}
466 master: {{ config.salt.salt_master_host }}
467 EOF
468 eatmydata apt-get install -y salt-minion;
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300469 service salt-minion restart; # For case if salt-minion was already installed
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300470 node_name: {{ ssh['node_name'] }}
471 retry: {count: 1, delay: 1}
472 skip_fail: false
473{% endfor %}
474
475
476- description: Accept salt keys from all the nodes
477 cmd: salt-key -A -y
478 node_name: {{ HOSTNAME_CFG01 }}
479 retry: {count: 1, delay: 5}
480 skip_fail: true
481{%- endmacro %}
482
483
484{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
485{##################################################}
486
487{# Prepare salt services and nodes settings #}
488
489- description: Run 'linux' formula on cfg01
490 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
491 node_name: {{ HOSTNAME_CFG01 }}
492 retry: {count: 3, delay: 5}
493 skip_fail: false
494
495- description: Run 'openssh' formula on cfg01
496 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300497 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300498 salt --hard-crash --state-output=mixed --state-verbose=False
499 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300500 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300501 node_name: {{ HOSTNAME_CFG01 }}
502 retry: {count: 3, delay: 5}
503 skip_fail: false
504
505- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
506 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
507 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
508 node_name: {{ HOSTNAME_CFG01 }}
509 retry: {count: 1, delay: 1}
510 skip_fail: false
511
512- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300513 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 +0300514 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300515 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300516 skip_fail: false
517
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400518{%- if SALT_FORMULAS_REFS != '' %}
519- description: Replace needed formulas to desired version
520 cmd: |
521 set -e;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400522 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
523 {% set formula = formula_set.split(':') %}
524 {% set formula_name = formula[0] %}
525 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300526 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400527 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
528 pushd {{ formula_dir }} &&
529 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
530 git checkout FETCH_HEAD &&
531 popd &&
532 if [ -d "{{ formula_dir }}" ]; then
533 echo "Going to replace packaged formula {{ formula_name }}" &&
534 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400535 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
536 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400537 else
538 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
539 fi
540 {%- endfor %}
541 node_name: {{ HOSTNAME_CFG01 }}
542 retry: {count: 1, delay: 10}
543 skip_fail: false
544{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300545
546- description: Refresh pillars on salt-master minion
547 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
548 node_name: {{ HOSTNAME_CFG01 }}
549 retry: {count: 1, delay: 5}
550 skip_fail: false
551
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300552- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300553 cmd: reclass-salt --top
554 node_name: {{ HOSTNAME_CFG01 }}
555 retry: {count: 1, delay: 5}
556 skip_fail: false
557
558- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300559 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 +0300560 node_name: {{ HOSTNAME_CFG01 }}
561 retry: {count: 1, delay: 5}
562 skip_fail: false
563
564- description: Configure linux on master
565 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
566 node_name: {{ HOSTNAME_CFG01 }}
567 retry: {count: 1, delay: 5}
568 skip_fail: false
569
570- description: Configure salt.minion on master
571 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
572 -C 'I@salt:master' state.sls salt.minion && sleep 10
573 node_name: {{ HOSTNAME_CFG01 }}
574 retry: {count: 3, delay: 10}
575 skip_fail: false
576
577- description: Run state 'salt' on master (for salt.api, etc)
578 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
579 -C 'I@salt:master' state.sls salt
580 node_name: {{ HOSTNAME_CFG01 }}
581 retry: {count: 3, delay: 10}
582 skip_fail: false
583{%- endmacro %}
584
585{%- macro MACRO_GENERATE_INVENTORY() %}
586{#####################################}
587- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
588 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
589 -C 'I@salt:master' state.sls reclass
590 node_name: {{ HOSTNAME_CFG01 }}
591 retry: {count: 1, delay: 5}
592 skip_fail: false
593
594- description: Refresh pillars on all minions
595 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
596 node_name: {{ HOSTNAME_CFG01 }}
597 retry: {count: 1, delay: 5}
598 skip_fail: false
599
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300600- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300601 cmd: |
602 set -e
603 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
604 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
605 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300606 node_name: {{ HOSTNAME_CFG01 }}
607 retry: {count: 1, delay: 5}
608 skip_fail: false
609
610- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300611 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300612 node_name: {{ HOSTNAME_CFG01 }}
613 retry: {count: 1, delay: 5}
614 skip_fail: false
615{%- endmacro %}
616
617
618{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
619{########################################}
620# Bootstrap all nodes
621- description: Configure linux on other nodes
622 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
623 node_name: {{ HOSTNAME_CFG01 }}
624 retry: {count: 5, delay: 10}
625 skip_fail: false
626
627- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300628 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 +0300629 salt --hard-crash --state-output=mixed --state-verbose=False
630 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
631 yes/' /etc/ssh/sshd_config && service ssh reload"
632 node_name: {{ HOSTNAME_CFG01 }}
633 retry: {count: 1, delay: 5}
634 skip_fail: false
635
636- description: Configure salt.minion on other nodes
637 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion &&
638 sleep 10
639 node_name: {{ HOSTNAME_CFG01 }}
640 retry: {count: 3, delay: 15}
641 skip_fail: false
642
643- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400644 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300645 node_name: {{ HOSTNAME_CFG01 }}
646 retry: {count: 3, delay: 15}
647 skip_fail: false
648
649- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400650 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300651 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400652 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300653 skip_fail: false
654
655- description: Configure ntp and rsyslog on nodes
656 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
657 node_name: {{ HOSTNAME_CFG01 }}
658 retry: {count: 1, delay: 10}
659 skip_fail: false
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200660{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300661
662
663{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
664{#########################################}
665
Oleksii Butenkof72f9d12017-10-18 13:10:04 +0300666#- description: '*Workaround 1/2* of the bug PROD-9576 to get bond0-connectivity *without* rebooting nodes'
667# cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False cmd.run
668# "mkdir -p /tmp/PROD-9576; cd /tmp/PROD-9576; git clone https://gerrit.mcp.mirantis.net/salt-formulas/linux; cd linux;
669# git fetch https://gerrit.mcp.mirantis.net/salt-formulas/linux refs/changes/54/2354/16 && git checkout FETCH_HEAD;
670# cp -f linux/network/interface.sls /srv/salt/env/prd/linux/network/;
671# cp -f linux/map.jinja /srv/salt/env/prd/linux/;"
672# node_name: {{ HOSTNAME_CFG01 }}
673# retry: {count: 1, delay: 5}
674# skip_fail: false
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300675
676- description: '*Workaround: Load bonding module before call state.linux'
677 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
678 node_name: {{ HOSTNAME_CFG01 }}
679 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +0300680 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300681
682- description: '*Workaround* install bridge-utils before running linux formula'
683 # The formula removes default route and then tries to install the package, fails.
684 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
685 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
686 node_name: {{ HOSTNAME_CFG01 }}
687 retry: {count: 1, delay: 5}
688 skip_fail: false
689
690{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400691
692{%- macro ADJUST_K8S_OPTS() %}
693{#########################################}
694
695- description: Set k8s deploy parameters
696 cmd: |
697 {% for k8s_opt, value in config.k8s_deploy.items() %}
698 {% if value|string() %}
699 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
700 {% endif %}
701 {% endfor %}
702 node_name: {{ HOSTNAME_CFG01 }}
703 retry: {count: 1, delay: 1}
704 skip_fail: false
705
706{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400707
708{%- macro REGISTER_COMPUTE_NODES() %}
709{#########################################}
710
711{% for ssh in config.underlay.ssh %}
712{% if ssh["node_name"].startswith("cmp") %}
713{% set node_hostname = ssh["node_name"].split('.')[0] %}
714- description: Register compute {{ ssh['node_name'] }}
715 cmd: |
716 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
717 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
718 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400719 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400720 export config_host={{ config.salt.salt_master_host }}
721 export node_domain={{ DOMAIN_NAME }}
722 export nodes_os="xenial"
723 export node_hostname={{ node_hostname }}
724 set -xe
725 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
726 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
727 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
728 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
729
730 # Add wrapper to apt-get to avoid race conditions
731 # with cron jobs running 'unattended-upgrades' script
732 aptget_wrapper() {
733 local apt_wrapper_timeout=300
734 local start_time=$(date '+%s')
735 local fin_time=$((start_time + apt_wrapper_timeout))
736 while true; do
737 if (( "$(date '+%s')" > fin_time )); then
738 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
739 fi
740 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
741 echo "Waiting while another apt/dpkg process releases locks ..."
742 sleep 30
743 continue
744 else
745 apt-get $@
746 break
747 fi
748 done
749 }
750
751 # Set default salt version
752 if [ -z "$saltversion" ]; then
753 saltversion="2016.3"
754 fi
755 echo "Using Salt version $saltversion"
756
757 echo "Preparing base OS ..."
758
759 case "$node_os" in
760 trusty)
761 # workaround for old cloud-init only configuring the first iface
762 iface_config_dir="/etc/network/interfaces"
763 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
764
765 for iface in $ifaces; do
766 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
767 done
768
769 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
770
771 # SUGGESTED UPDATE:
772 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
773 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
774 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
775 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
776 #install_salt_minion_pkg
777
778 # DEPRECATED:
779 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
780 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
781
782 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
783 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
784
785 aptget_wrapper clean
786 aptget_wrapper update
787 aptget_wrapper install -y salt-common
788 aptget_wrapper install -y salt-minion
789 ;;
790 xenial)
791
792 # workaround for new cloud-init setting all interfaces statically
793 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
794
795 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
796
797 # SUGGESTED UPDATE:
798 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
799 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
800 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
801 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
802 #install_salt_minion_pkg
803
804 # DEPRECATED:
805 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
806 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
807
808 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
809 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
810
811 aptget_wrapper clean
812 aptget_wrapper update
813 aptget_wrapper install -y salt-minion
814 ;;
815 rhel|centos|centos7|centos7|rhel6|rhel7)
816 yum install -y git
817 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
818 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
819 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
820 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
821 install_salt_minion_pkg
822 ;;
823 *)
824 msg="OS '$node_os' is not supported."
825 esac
826
827 echo "Configuring Salt minion ..."
828 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
829 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
830
831 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
832
833 sleep 1
834
835 echo "Classifying node ..."
836 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
837 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
838 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
839 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
840 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
841 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
842
843 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
844 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
845 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
846 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
847 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
848
849 if [ "$node_network05_iface" != "" ]; then
850 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
851 fi
852
853 # find more parameters (every env starting param_)
854 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
855 if [ "$more_params" != "" ]; then
856 echo "Additional params: $more_params"
857 more_params=", $more_params"
858 fi
859
860 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}}"
861
862 sleep 5
863
864 salt-call saltutil.sync_all
865 salt-call mine.flush
866 salt-call mine.update
867 node_name: {{ ssh['node_name'] }}
868 retry: {count: 1, delay: 1}
869 skip_fail: false
870{%- endif %}
871{%- endfor %}
872
873- description: Refresh pillars on all minions
874 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
875 node_name: {{ HOSTNAME_CFG01 }}
876 retry: {count: 1, delay: 5}
877 skip_fail: false
878
879- description: Sync all salt resources
880 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
881 node_name: {{ HOSTNAME_CFG01 }}
882 retry: {count: 1, delay: 5}
883 skip_fail: false
884
sgudz160b7302017-12-22 17:01:10 +0200885{%- endmacro %}