blob: 11c638001b00987c31a7b28bea17a9bd11827178 [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','') %}
sgudza399dc72018-01-18 17:13:48 +020012{% set COOKIECUTTER_TEMPLATE_COMMIT = os_env('COOKIECUTTER_TEMPLATE_COMMIT','') %}
sgudzcced67d2017-10-11 15:56:09 +030013{% set ENVIRONMENT_TEMPLATE_REF_CHANGE = os_env('ENVIRONMENT_TEMPLATE_REF_CHANGE','') %}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020014
Dennis Dmitriev492813e2017-08-09 15:08:58 +030015{% set REPOSITORY_SUITE = os_env('REPOSITORY_SUITE', 'testing') %}
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020016{% set FORMULA_REPOSITORY = os_env('FORMULA_REPOSITORY', 'deb [arch=amd64] http://apt.mirantis.com/xenial ' + REPOSITORY_SUITE + ' salt') %}
17{% set FORMULA_GPG = os_env('FORMULA_GPG', 'http://apt.mirantis.com/public.gpg') %}
18{% set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb http://repo.saltstack.local.test/apt/ubuntu/16.04/amd64/2016.3 xenial main") %}
19{% set SALT_GPG = os_env('SALT_GPG', 'http://repo.saltstack.local.test/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub') %}
20{% set UBUNTU_REPOSITORY = os_env('UBUNTU_REPOSITORY', "deb http://archive.ubuntu.com/ubuntu/ xenial main universe restricted") %}
21{% set UBUNTU_UPDATES_REPOSITORY = os_env('UBUNTU_UPDATES_REPOSITORY', "deb http://archive.ubuntu.com/ubuntu/ xenial-updates main universe restricted") %}
22{% 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 +030023
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020024{# Address pools for reclass cluster model are taken in the following order:
25 # 1. environment variables,
26 # 2. config.underlay.address_pools based on fuel-devops address pools
27 # (see generated '.ini' file after underlay is created),
28 # 3. defaults #}
29{% set address_pools = config.underlay.address_pools %}
30{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
31{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
32{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
33{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
34{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
35{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
36{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
37{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
38
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040039{# Format for formula replacement:
40 # space separated string:
41 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
42
43{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
44{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.net/salt-formulas') %}
45
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040046# Needed for using different models in different templates
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020047{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040048
Dennis Dmitriev492813e2017-08-09 15:08:58 +030049
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020050{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
51{#####################################################}
52
53- description: 'Configure key on nodes and install packages'
54 cmd: |
55 rm -rf trusted* ;
56 rm -rf /etc/apt/sources.list ;
57 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
58 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
59 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
60 wget -O - "{{ SALT_GPG }}" | apt-key add -;
61 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
62 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
63 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
64 eatmydata apt-get clean && apt-get update;
65 node_name: {{ NODE_NAME }}
66 retry: {count: 1, delay: 5}
67 skip_fail: false
68
69{%- endmacro %}
70
71
Dennis Dmitriev492813e2017-08-09 15:08:58 +030072{%- macro MACRO_INSTALL_SALT_MASTER() %}
73{######################################}
74- description: Installing salt master on cfg01
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020075 cmd: eatmydata apt-get install -y --allow-unauthenticated reclass git salt-master
Dennis Dmitriev492813e2017-08-09 15:08:58 +030076 node_name: {{ HOSTNAME_CFG01 }}
77 retry: {count: 1, delay: 1}
78 skip_fail: false
79
Dennis Dmitrievda9be462018-01-24 21:20:09 +020080- description: Remove any existing minion keys
81 cmd: salt-key -y -D || true
82 node_name: {{ HOSTNAME_CFG01 }}
83 retry: {count: 1, delay: 1}
84 skip_fail: false
85
Dennis Dmitriev492813e2017-08-09 15:08:58 +030086- description: Configure salt-master on cfg01
87 cmd: |
Dennis Dmitrieva578c772018-01-24 21:02:15 +020088 cat << 'EOF' > /etc/salt/master.d/master.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +030089 file_roots:
90 base:
91 - /usr/share/salt-formulas/env
92 pillar_opts: False
93 open_mode: True
94 reclass: &reclass
95 storage_type: yaml_fs
96 inventory_base_uri: /srv/salt/reclass
97 ext_pillar:
98 - reclass: *reclass
99 master_tops:
100 reclass: *reclass
101 EOF
102 node_name: {{ HOSTNAME_CFG01 }}
103 retry: {count: 1, delay: 1}
104 skip_fail: false
105
106- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300107 cmd: |
108 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200109 #touch /root/.git_trusted_certs.pem;
110 #for server in github.com; do \
111 # openssl s_client -showcerts -connect $server:443 </dev/null \
112 # | openssl x509 -outform PEM \
113 # >> /root/.git_trusted_certs.pem;
114 #done;
115 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
116 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
117 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300118 node_name: {{ HOSTNAME_CFG01 }}
119 retry: {count: 1, delay: 1}
120 skip_fail: false
121{%- endmacro %}
122
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300123{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false) %}
124{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300125{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
126
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300127- description: Clone reclass models with submodules
128 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300129 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200130 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200131 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200132
133 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
134 export GIT_SSL_NO_VERIFY=true; git clone -b {{ SALT_MODELS_BRANCH }} {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass.tmp;
Dennis Dmitriev70dd3062018-01-24 20:45:49 +0200135 rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200136
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200137 pushd /srv/salt/reclass;
138 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
139 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200140 {%- if SALT_MODELS_REF_CHANGE != '' %}
141 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200142 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200143 {%- endfor %}
144 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200145 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200146 {%- endif %}
147 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200148 pushd classes/system/;
149 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
150 popd;
sgudz4d816eb2017-11-13 11:58:05 +0200151 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300152 pushd classes/system/ && \
153 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200154 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300155 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200156 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200157 {%- endif %}
158 popd;
159 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrieva14f5562017-10-02 12:59:53 +0300160 rm -rf /srv/salt/reclass/nodes/ # For backward compatibility. New cfg node will be regenerated here
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300161 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200162
163 # Replace firstly to an intermediate value to avoid intersection between
164 # already replaced and replacing networks.
165 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
166 # 192.168.10 -> 10.16.0 (generated network for admin)
167 # 10.16.0 -> <external network>
168 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300169 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
170 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
171 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
172 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} +
173 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200174
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300175 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
176 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
177 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} +
178 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 +0200179
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300180 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 +0200181
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300182 {%- if IS_CONTRAIL_LAB %}
183 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300184 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 +0300185 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 +0300186 {%- endif %}
187
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200188 # Override some context parameters
189 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
190 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
191 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
192
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200193 # Disable checkouting the model from remote repository
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200194 cat << 'EOF' > /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300195 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400196 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300197 parameters:
198 _param:
199 linux_system_codename: xenial
200 reclass_data_revision: master
201 linux:
202 system:
203 name: cfg01
204 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200205 reclass:
206 storage:
207 data_source:
208 engine: local
209 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300210
211 # Show the changes to the console
212 cd /srv/salt/reclass/; git diff
213 node_name: {{ HOSTNAME_CFG01 }}
214 retry: {count: 1, delay: 1}
215 skip_fail: false
216{%- endmacro %}
217
218
sgudz160b7302017-12-22 17:01:10 +0200219{%- 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 +0300220{###################################################################}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300221{%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300222- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to {{ HOSTNAME_CFG01 }}"
223 upload:
224 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
225 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300226 remote_path: /tmp/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300227 node_name: {{ HOSTNAME_CFG01 }}
228
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300229- description: Create cluster model from cookiecutter templates
230 cmd: |
231 set -e;
232 pip install cookiecutter
233 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 +0200234
sgudza399dc72018-01-18 17:13:48 +0200235 {%- if COOKIECUTTER_TEMPLATE_COMMIT != '' %}
236 pushd /tmp/cookiecutter-templates
237 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
238 popd
239 {%- endif %}
240
sgudz4d816eb2017-11-13 11:58:05 +0200241 {%- if COOKIECUTTER_REF_CHANGE != '' %}
242 pushd /tmp/cookiecutter-templates
243 git fetch https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
244 popd
245 {%- endif %}
246
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300247 mkdir -p /srv/salt/reclass/classes/cluster/
248 mkdir -p /srv/salt/reclass/classes/system/
249 mkdir -p /srv/salt/reclass/classes/service/
Dennis Dmitrieva14f5562017-10-02 12:59:53 +0300250 rm -rf /srv/salt/reclass/nodes/ # For backward compatibility. New cfg node will be regenerated here
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300251 mkdir -p /srv/salt/reclass/nodes/_generated
252
253 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200254 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
255 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200256 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300257 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200258 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300259 {%- endif %}
260 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200261 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300262 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300263
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300264 # Replace firstly to an intermediate value to avoid intersection between
265 # already replaced and replacing networks.
266 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
267 # 192.168.10 -> 10.16.0 (generated network for admin)
268 # 10.16.0 -> <external network>
269 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
270 sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
271 sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
272 sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
273 sed -i 's/172\.17\.16\./==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
274
Dennis Dmitriev39e64bd2017-09-21 22:37:40 +0300275 sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
276 sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
277 sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
278 sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300279
sgudz160b7302017-12-22 17:01:10 +0200280 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /tmp/cookiecutter-templates/cluster_product/)' %}
281 for item in {{ items }}; do
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300282 python /tmp/cookiecutter-templates/generate.py \
sgudz160b7302017-12-22 17:01:10 +0200283 --template /tmp/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300284 --config-file {{ CLUSTER_CONTEXT_PATH }} \
285 --output-dir /srv/salt/reclass/classes/cluster/;
286 done
287
288 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/
289
290 # Create the cfg01 node and disable checkouting the model from remote repository
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200291 cat << 'EOF' > /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300292 classes:
293 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200294 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300295 EOF
296
297 node_name: {{ HOSTNAME_CFG01 }}
298 retry: {count: 1, delay: 1}
299 skip_fail: false
300
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300301- description: Modify generated model and reclass-system if necessary
302 cmd: |
303 set -e;
304 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
305 pushd /srv/salt/reclass/classes/system/
306 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
307 popd
sgudz4d816eb2017-11-13 11:58:05 +0200308 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300309 pushd /srv/salt/reclass/classes/system/
310 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
311 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD
312 {%- endfor %}
313 popd
314 {%- endif %}
315
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300316 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200317 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300318 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
319 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
320 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
321 {%- endif %}
322
323 node_name: {{ HOSTNAME_CFG01 }}
324 retry: {count: 1, delay: 1}
325 skip_fail: false
326{%- endmacro %}
327
328
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300329{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
330{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300331
sgudzcced67d2017-10-11 15:56:09 +0300332- description: "[EXPERIMENTAL] Clone 'environment-template' repository to {{ HOSTNAME_CFG01 }}."
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300333 cmd: |
334 set -e;
335 mkdir -p /tmp/environment/;
336 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 +0300337 node_name: {{ HOSTNAME_CFG01 }}
338 skip_fail: false
339
sgudzcced67d2017-10-11 15:56:09 +0300340{%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
341- description: Fetch changes for environment templates
342 cmd: |
343 set -e;
344 pushd /tmp/environment/environment_template &&
345 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
346 git checkout FETCH_HEAD &&
347 popd
348 node_name: {{ HOSTNAME_CFG01 }}
349 skip_fail: false
350{%- endif %}
351
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300352{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300353- description: "[EXPERIMENTAL] Upload environment inventory to {{ HOSTNAME_CFG01 }}"
354 upload:
355 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
356 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
357 remote_path: /tmp/environment/
358 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300359{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300360
361- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
362 cmd: |
363 set -e;
364 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
365 pip install git+https://github.com/dis-xcom/reclass-tools;
366 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
367 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
368 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
369
370 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
371 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml --merge ;
372 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}' /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml --merge ;
373 fi;
374
375 node_name: {{ HOSTNAME_CFG01 }}
376 retry: {count: 1, delay: 5}
377 skip_fail: false
378
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200379- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300380 cmd: |
381 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200382 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 +0300383
384 node_name: {{ HOSTNAME_CFG01 }}
385 retry: {count: 1, delay: 5}
386 skip_fail: false
387
388- description: "[EXPERIMENTAL] Create environment model for virtual environment"
389 cmd: |
390 set -e;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300391 reclass-tools render --template-dir /tmp/environment/environment_template/ \
392 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitrievd55a8562017-09-28 22:12:09 +0300393 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /tmp/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300394 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
395 node_name: {{ HOSTNAME_CFG01 }}
396 retry: {count: 1, delay: 5}
397 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300398
399- description: Modify generated model and reclass-system
400 cmd: |
401 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
402 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
403 node_name: {{ HOSTNAME_CFG01 }}
404 retry: {count: 1, delay: 1}
405 skip_fail: false
406
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300407{%- endmacro %}
408
409
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300410{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
411{#######################################################}
412- description: Configure reclass
413 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300414 set -e;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300415 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300416 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200417 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
418 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300419 apt-get clean; apt-get update;
420 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
421 declare -a formula_services=({{ FORMULA_SERVICES }});
422 echo -e "\nInstalling all required salt formulas\n";
423 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
424 for formula_service in "${formula_services[@]}"; do
425 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
426 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
427 done;
428 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
429 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
430 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
431
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200432 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300433 storage_type: yaml_fs
434 pretty_print: True
435 output: yaml
436 inventory_base_uri: /srv/salt/reclass
437 EOF
438 node_name: {{ HOSTNAME_CFG01 }}
439 retry: {count: 1, delay: 1}
440 skip_fail: false
441
442- description: "*Workaround* remove all cfg01 nodes except {{ HOSTNAME_CFG01 }} to not depend on other clusters in 'reclass --top'"
443 cmd: |
444 # Remove all other nodes except {{ HOSTNAME_CFG01 }} to not rely on them for 'reclass --top'
445 find /srv/salt/reclass/nodes/ -type f -not -name {{ HOSTNAME_CFG01 }}.yml -delete
446 node_name: {{ HOSTNAME_CFG01 }}
447 retry: {count: 1, delay: 5}
448 skip_fail: false
449
450- description: Configure salt adoptors on cfg01
451 cmd: |
452 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
453 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
454 node_name: {{ HOSTNAME_CFG01 }}
455 retry: {count: 1, delay: 1}
456 skip_fail: false
457
458- description: Show reclass-salt --top for cfg01 node
459 cmd: reclass-salt --top
460 node_name: {{ HOSTNAME_CFG01 }}
461 retry: {count: 1, delay: 5}
462 skip_fail: false
463
464- description: Restart salt-master service
465 cmd: systemctl restart salt-master;
466 node_name: {{ HOSTNAME_CFG01 }}
467 retry: {count: 1, delay: 5}
468 skip_fail: false
469{%- endmacro %}
470
471
472{%- macro MACRO_INSTALL_SALT_MINIONS() %}
473{#######################################}
474{% for ssh in config.underlay.ssh %}
475- description: Configure salt-minion on {{ ssh['node_name'] }}
476 cmd: |
477 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200478 cat << "EOF" > /etc/salt/minion.d/minion.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300479 id: {{ ssh['node_name'] }}
480 master: {{ config.salt.salt_master_host }}
481 EOF
482 eatmydata apt-get install -y salt-minion;
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300483 service salt-minion restart; # For case if salt-minion was already installed
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300484 node_name: {{ ssh['node_name'] }}
485 retry: {count: 1, delay: 1}
486 skip_fail: false
487{% endfor %}
488
489
490- description: Accept salt keys from all the nodes
491 cmd: salt-key -A -y
492 node_name: {{ HOSTNAME_CFG01 }}
493 retry: {count: 1, delay: 5}
494 skip_fail: true
495{%- endmacro %}
496
497
498{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
499{##################################################}
500
501{# Prepare salt services and nodes settings #}
502
503- description: Run 'linux' formula on cfg01
504 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
505 node_name: {{ HOSTNAME_CFG01 }}
506 retry: {count: 3, delay: 5}
507 skip_fail: false
508
509- description: Run 'openssh' formula on cfg01
510 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300511 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300512 salt --hard-crash --state-output=mixed --state-verbose=False
513 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300514 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300515 node_name: {{ HOSTNAME_CFG01 }}
516 retry: {count: 3, delay: 5}
517 skip_fail: false
518
519- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
520 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
521 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
522 node_name: {{ HOSTNAME_CFG01 }}
523 retry: {count: 1, delay: 1}
524 skip_fail: false
525
526- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300527 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 +0300528 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300529 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300530 skip_fail: false
531
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400532{%- if SALT_FORMULAS_REFS != '' %}
533- description: Replace needed formulas to desired version
534 cmd: |
535 set -e;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400536 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
537 {% set formula = formula_set.split(':') %}
538 {% set formula_name = formula[0] %}
539 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300540 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400541 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
542 pushd {{ formula_dir }} &&
543 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
544 git checkout FETCH_HEAD &&
545 popd &&
546 if [ -d "{{ formula_dir }}" ]; then
547 echo "Going to replace packaged formula {{ formula_name }}" &&
548 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400549 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
550 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400551 else
552 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
553 fi
554 {%- endfor %}
555 node_name: {{ HOSTNAME_CFG01 }}
556 retry: {count: 1, delay: 10}
557 skip_fail: false
558{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300559
560- description: Refresh pillars on salt-master minion
561 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
562 node_name: {{ HOSTNAME_CFG01 }}
563 retry: {count: 1, delay: 5}
564 skip_fail: false
565
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300566- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300567 cmd: reclass-salt --top
568 node_name: {{ HOSTNAME_CFG01 }}
569 retry: {count: 1, delay: 5}
570 skip_fail: false
571
572- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300573 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 +0300574 node_name: {{ HOSTNAME_CFG01 }}
575 retry: {count: 1, delay: 5}
576 skip_fail: false
577
578- description: Configure linux on master
579 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
580 node_name: {{ HOSTNAME_CFG01 }}
581 retry: {count: 1, delay: 5}
582 skip_fail: false
583
584- description: Configure salt.minion on master
585 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
586 -C 'I@salt:master' state.sls salt.minion && sleep 10
587 node_name: {{ HOSTNAME_CFG01 }}
588 retry: {count: 3, delay: 10}
589 skip_fail: false
590
591- description: Run state 'salt' on master (for salt.api, etc)
592 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
593 -C 'I@salt:master' state.sls salt
594 node_name: {{ HOSTNAME_CFG01 }}
595 retry: {count: 3, delay: 10}
596 skip_fail: false
597{%- endmacro %}
598
599{%- macro MACRO_GENERATE_INVENTORY() %}
600{#####################################}
601- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
602 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
603 -C 'I@salt:master' state.sls reclass
604 node_name: {{ HOSTNAME_CFG01 }}
605 retry: {count: 1, delay: 5}
606 skip_fail: false
607
608- description: Refresh pillars on all minions
609 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
610 node_name: {{ HOSTNAME_CFG01 }}
611 retry: {count: 1, delay: 5}
612 skip_fail: false
613
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300614- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300615 cmd: |
616 set -e
617 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
618 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
619 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300620 node_name: {{ HOSTNAME_CFG01 }}
621 retry: {count: 1, delay: 5}
622 skip_fail: false
623
624- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300625 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300626 node_name: {{ HOSTNAME_CFG01 }}
627 retry: {count: 1, delay: 5}
628 skip_fail: false
629{%- endmacro %}
630
631
632{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
633{########################################}
634# Bootstrap all nodes
635- description: Configure linux on other nodes
636 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
637 node_name: {{ HOSTNAME_CFG01 }}
638 retry: {count: 5, delay: 10}
639 skip_fail: false
640
641- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300642 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 +0300643 salt --hard-crash --state-output=mixed --state-verbose=False
644 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
645 yes/' /etc/ssh/sshd_config && service ssh reload"
646 node_name: {{ HOSTNAME_CFG01 }}
647 retry: {count: 1, delay: 5}
648 skip_fail: false
649
650- description: Configure salt.minion on other nodes
651 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion &&
652 sleep 10
653 node_name: {{ HOSTNAME_CFG01 }}
654 retry: {count: 3, delay: 15}
655 skip_fail: false
656
657- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400658 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300659 node_name: {{ HOSTNAME_CFG01 }}
660 retry: {count: 3, delay: 15}
661 skip_fail: false
662
663- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400664 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300665 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400666 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300667 skip_fail: false
668
669- description: Configure ntp and rsyslog on nodes
670 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
671 node_name: {{ HOSTNAME_CFG01 }}
672 retry: {count: 1, delay: 10}
673 skip_fail: false
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200674{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300675
676
677{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
678{#########################################}
679
Oleksii Butenkof72f9d12017-10-18 13:10:04 +0300680#- description: '*Workaround 1/2* of the bug PROD-9576 to get bond0-connectivity *without* rebooting nodes'
681# cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False cmd.run
682# "mkdir -p /tmp/PROD-9576; cd /tmp/PROD-9576; git clone https://gerrit.mcp.mirantis.net/salt-formulas/linux; cd linux;
683# git fetch https://gerrit.mcp.mirantis.net/salt-formulas/linux refs/changes/54/2354/16 && git checkout FETCH_HEAD;
684# cp -f linux/network/interface.sls /srv/salt/env/prd/linux/network/;
685# cp -f linux/map.jinja /srv/salt/env/prd/linux/;"
686# node_name: {{ HOSTNAME_CFG01 }}
687# retry: {count: 1, delay: 5}
688# skip_fail: false
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300689
690- description: '*Workaround: Load bonding module before call state.linux'
691 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
692 node_name: {{ HOSTNAME_CFG01 }}
693 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +0300694 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300695
696- description: '*Workaround* install bridge-utils before running linux formula'
697 # The formula removes default route and then tries to install the package, fails.
698 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
699 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
700 node_name: {{ HOSTNAME_CFG01 }}
701 retry: {count: 1, delay: 5}
702 skip_fail: false
703
704{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400705
706{%- macro ADJUST_K8S_OPTS() %}
707{#########################################}
708
709- description: Set k8s deploy parameters
710 cmd: |
711 {% for k8s_opt, value in config.k8s_deploy.items() %}
712 {% if value|string() %}
713 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
714 {% endif %}
715 {% endfor %}
716 node_name: {{ HOSTNAME_CFG01 }}
717 retry: {count: 1, delay: 1}
718 skip_fail: false
719
720{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400721
722{%- macro REGISTER_COMPUTE_NODES() %}
723{#########################################}
724
725{% for ssh in config.underlay.ssh %}
726{% if ssh["node_name"].startswith("cmp") %}
727{% set node_hostname = ssh["node_name"].split('.')[0] %}
728- description: Register compute {{ ssh['node_name'] }}
729 cmd: |
730 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
731 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
732 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400733 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400734 export config_host={{ config.salt.salt_master_host }}
735 export node_domain={{ DOMAIN_NAME }}
736 export nodes_os="xenial"
737 export node_hostname={{ node_hostname }}
738 set -xe
739 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
740 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
741 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
742 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
743
744 # Add wrapper to apt-get to avoid race conditions
745 # with cron jobs running 'unattended-upgrades' script
746 aptget_wrapper() {
747 local apt_wrapper_timeout=300
748 local start_time=$(date '+%s')
749 local fin_time=$((start_time + apt_wrapper_timeout))
750 while true; do
751 if (( "$(date '+%s')" > fin_time )); then
752 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
753 fi
754 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
755 echo "Waiting while another apt/dpkg process releases locks ..."
756 sleep 30
757 continue
758 else
759 apt-get $@
760 break
761 fi
762 done
763 }
764
765 # Set default salt version
766 if [ -z "$saltversion" ]; then
767 saltversion="2016.3"
768 fi
769 echo "Using Salt version $saltversion"
770
771 echo "Preparing base OS ..."
772
773 case "$node_os" in
774 trusty)
775 # workaround for old cloud-init only configuring the first iface
776 iface_config_dir="/etc/network/interfaces"
777 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
778
779 for iface in $ifaces; do
780 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
781 done
782
783 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
784
785 # SUGGESTED UPDATE:
786 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
787 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
788 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
789 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
790 #install_salt_minion_pkg
791
792 # DEPRECATED:
793 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
794 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
795
796 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
797 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
798
799 aptget_wrapper clean
800 aptget_wrapper update
801 aptget_wrapper install -y salt-common
802 aptget_wrapper install -y salt-minion
803 ;;
804 xenial)
805
806 # workaround for new cloud-init setting all interfaces statically
807 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
808
809 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
810
811 # SUGGESTED UPDATE:
812 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
813 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
814 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
815 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
816 #install_salt_minion_pkg
817
818 # DEPRECATED:
819 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
820 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
821
822 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
823 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
824
825 aptget_wrapper clean
826 aptget_wrapper update
827 aptget_wrapper install -y salt-minion
828 ;;
829 rhel|centos|centos7|centos7|rhel6|rhel7)
830 yum install -y git
831 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
832 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
833 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
834 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
835 install_salt_minion_pkg
836 ;;
837 *)
838 msg="OS '$node_os' is not supported."
839 esac
840
841 echo "Configuring Salt minion ..."
842 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
843 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
844
845 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
846
847 sleep 1
848
849 echo "Classifying node ..."
850 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
851 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
852 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
853 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
854 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
855 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
856
857 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
858 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
859 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
860 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
861 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
862
863 if [ "$node_network05_iface" != "" ]; then
864 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
865 fi
866
867 # find more parameters (every env starting param_)
868 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
869 if [ "$more_params" != "" ]; then
870 echo "Additional params: $more_params"
871 more_params=", $more_params"
872 fi
873
874 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}}"
875
876 sleep 5
877
878 salt-call saltutil.sync_all
879 salt-call mine.flush
880 salt-call mine.update
881 node_name: {{ ssh['node_name'] }}
882 retry: {count: 1, delay: 1}
883 skip_fail: false
884{%- endif %}
885{%- endfor %}
886
887- description: Refresh pillars on all minions
888 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
889 node_name: {{ HOSTNAME_CFG01 }}
890 retry: {count: 1, delay: 5}
891 skip_fail: false
892
893- description: Sync all salt resources
894 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
895 node_name: {{ HOSTNAME_CFG01 }}
896 retry: {count: 1, delay: 5}
897 skip_fail: false
898
sgudz160b7302017-12-22 17:01:10 +0200899{%- endmacro %}