blob: 5b5dd507832da3fb6a3427f5597781d973203f07 [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
80- description: Configure salt-master on cfg01
81 cmd: |
82 cat << 'EOF' >> /etc/salt/master.d/master.conf
83 file_roots:
84 base:
85 - /usr/share/salt-formulas/env
86 pillar_opts: False
87 open_mode: True
88 reclass: &reclass
89 storage_type: yaml_fs
90 inventory_base_uri: /srv/salt/reclass
91 ext_pillar:
92 - reclass: *reclass
93 master_tops:
94 reclass: *reclass
95 EOF
96 node_name: {{ HOSTNAME_CFG01 }}
97 retry: {count: 1, delay: 1}
98 skip_fail: false
99
100- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300101 cmd: |
102 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200103 #touch /root/.git_trusted_certs.pem;
104 #for server in github.com; do \
105 # openssl s_client -showcerts -connect $server:443 </dev/null \
106 # | openssl x509 -outform PEM \
107 # >> /root/.git_trusted_certs.pem;
108 #done;
109 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
110 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
111 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300112 node_name: {{ HOSTNAME_CFG01 }}
113 retry: {count: 1, delay: 1}
114 skip_fail: false
115{%- endmacro %}
116
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300117{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false) %}
118{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300119{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
120
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300121- description: Clone reclass models with submodules
122 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300123 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200124 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200125 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200126
127 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
128 export GIT_SSL_NO_VERIFY=true; git clone -b {{ SALT_MODELS_BRANCH }} {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass.tmp;
129 cp -r /srv/salt/reclass.tmp/* /srv/salt/reclass/
130 cp -r /srv/salt/reclass.tmp/.git /srv/salt/reclass/
131
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200132 pushd /srv/salt/reclass;
133 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
134 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200135 {%- if SALT_MODELS_REF_CHANGE != '' %}
136 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200137 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200138 {%- endfor %}
139 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200140 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200141 {%- endif %}
142 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200143 pushd classes/system/;
144 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
145 popd;
sgudz4d816eb2017-11-13 11:58:05 +0200146 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300147 pushd classes/system/ && \
148 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200149 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300150 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200151 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200152 {%- endif %}
153 popd;
154 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrieva14f5562017-10-02 12:59:53 +0300155 rm -rf /srv/salt/reclass/nodes/ # For backward compatibility. New cfg node will be regenerated here
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300156 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200157
158 # Replace firstly to an intermediate value to avoid intersection between
159 # already replaced and replacing networks.
160 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
161 # 192.168.10 -> 10.16.0 (generated network for admin)
162 # 10.16.0 -> <external network>
163 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300164 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
165 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
166 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
167 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} +
168 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200169
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300170 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
171 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
172 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} +
173 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 +0200174
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300175 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 +0200176
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300177 {%- if IS_CONTRAIL_LAB %}
178 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300179 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 +0300180 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 +0300181 {%- endif %}
182
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200183 # Override some context parameters
184 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
185 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
186 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
187
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200188 # Disable checkouting the model from remote repository
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300189 cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml
190 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400191 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300192 parameters:
193 _param:
194 linux_system_codename: xenial
195 reclass_data_revision: master
196 linux:
197 system:
198 name: cfg01
199 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200200 reclass:
201 storage:
202 data_source:
203 engine: local
204 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300205
206 # Show the changes to the console
207 cd /srv/salt/reclass/; git diff
208 node_name: {{ HOSTNAME_CFG01 }}
209 retry: {count: 1, delay: 1}
210 skip_fail: false
211{%- endmacro %}
212
213
sgudz160b7302017-12-22 17:01:10 +0200214{%- 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 +0300215{###################################################################}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300216{%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300217- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to {{ HOSTNAME_CFG01 }}"
218 upload:
219 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
220 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300221 remote_path: /tmp/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300222 node_name: {{ HOSTNAME_CFG01 }}
223
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300224- description: Create cluster model from cookiecutter templates
225 cmd: |
226 set -e;
227 pip install cookiecutter
228 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 +0200229
sgudza399dc72018-01-18 17:13:48 +0200230 {%- if COOKIECUTTER_TEMPLATE_COMMIT != '' %}
231 pushd /tmp/cookiecutter-templates
232 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
233 popd
234 {%- endif %}
235
sgudz4d816eb2017-11-13 11:58:05 +0200236 {%- if COOKIECUTTER_REF_CHANGE != '' %}
237 pushd /tmp/cookiecutter-templates
238 git fetch https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
239 popd
240 {%- endif %}
241
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300242 mkdir -p /srv/salt/reclass/classes/cluster/
243 mkdir -p /srv/salt/reclass/classes/system/
244 mkdir -p /srv/salt/reclass/classes/service/
Dennis Dmitrieva14f5562017-10-02 12:59:53 +0300245 rm -rf /srv/salt/reclass/nodes/ # For backward compatibility. New cfg node will be regenerated here
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300246 mkdir -p /srv/salt/reclass/nodes/_generated
247
248 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200249 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
250 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200251 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300252 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200253 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300254 {%- endif %}
255 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200256 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300257 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300258
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300259 # Replace firstly to an intermediate value to avoid intersection between
260 # already replaced and replacing networks.
261 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
262 # 192.168.10 -> 10.16.0 (generated network for admin)
263 # 10.16.0 -> <external network>
264 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
265 sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
266 sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
267 sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
268 sed -i 's/172\.17\.16\./==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
269
Dennis Dmitriev39e64bd2017-09-21 22:37:40 +0300270 sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
271 sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
272 sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
273 sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300274
sgudz160b7302017-12-22 17:01:10 +0200275 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /tmp/cookiecutter-templates/cluster_product/)' %}
276 for item in {{ items }}; do
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300277 python /tmp/cookiecutter-templates/generate.py \
sgudz160b7302017-12-22 17:01:10 +0200278 --template /tmp/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300279 --config-file {{ CLUSTER_CONTEXT_PATH }} \
280 --output-dir /srv/salt/reclass/classes/cluster/;
281 done
282
283 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/
284
285 # Create the cfg01 node and disable checkouting the model from remote repository
286 cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml
287 classes:
288 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200289 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300290 EOF
291
292 node_name: {{ HOSTNAME_CFG01 }}
293 retry: {count: 1, delay: 1}
294 skip_fail: false
295
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300296- description: Modify generated model and reclass-system if necessary
297 cmd: |
298 set -e;
299 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
300 pushd /srv/salt/reclass/classes/system/
301 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
302 popd
sgudz4d816eb2017-11-13 11:58:05 +0200303 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300304 pushd /srv/salt/reclass/classes/system/
305 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
306 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD
307 {%- endfor %}
308 popd
309 {%- endif %}
310
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300311 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200312 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300313 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
314 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
315 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
316 {%- endif %}
317
318 node_name: {{ HOSTNAME_CFG01 }}
319 retry: {count: 1, delay: 1}
320 skip_fail: false
321{%- endmacro %}
322
323
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300324{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
325{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300326
sgudzcced67d2017-10-11 15:56:09 +0300327- description: "[EXPERIMENTAL] Clone 'environment-template' repository to {{ HOSTNAME_CFG01 }}."
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300328 cmd: |
329 set -e;
330 mkdir -p /tmp/environment/;
331 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 +0300332 node_name: {{ HOSTNAME_CFG01 }}
333 skip_fail: false
334
sgudzcced67d2017-10-11 15:56:09 +0300335{%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
336- description: Fetch changes for environment templates
337 cmd: |
338 set -e;
339 pushd /tmp/environment/environment_template &&
340 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
341 git checkout FETCH_HEAD &&
342 popd
343 node_name: {{ HOSTNAME_CFG01 }}
344 skip_fail: false
345{%- endif %}
346
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300347{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300348- description: "[EXPERIMENTAL] Upload environment inventory to {{ HOSTNAME_CFG01 }}"
349 upload:
350 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
351 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
352 remote_path: /tmp/environment/
353 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300354{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300355
356- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
357 cmd: |
358 set -e;
359 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
360 pip install git+https://github.com/dis-xcom/reclass-tools;
361 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
362 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
363 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
364
365 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
366 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml --merge ;
367 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}' /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml --merge ;
368 fi;
369
370 node_name: {{ HOSTNAME_CFG01 }}
371 retry: {count: 1, delay: 5}
372 skip_fail: false
373
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200374- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300375 cmd: |
376 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200377 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 +0300378
379 node_name: {{ HOSTNAME_CFG01 }}
380 retry: {count: 1, delay: 5}
381 skip_fail: false
382
383- description: "[EXPERIMENTAL] Create environment model for virtual environment"
384 cmd: |
385 set -e;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300386 reclass-tools render --template-dir /tmp/environment/environment_template/ \
387 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitrievd55a8562017-09-28 22:12:09 +0300388 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /tmp/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300389 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
390 node_name: {{ HOSTNAME_CFG01 }}
391 retry: {count: 1, delay: 5}
392 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300393
394- description: Modify generated model and reclass-system
395 cmd: |
396 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
397 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
398 node_name: {{ HOSTNAME_CFG01 }}
399 retry: {count: 1, delay: 1}
400 skip_fail: false
401
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300402{%- endmacro %}
403
404
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300405{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
406{#######################################################}
407- description: Configure reclass
408 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300409 set -e;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300410 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300411 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200412 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
413 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300414 apt-get clean; apt-get update;
415 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
416 declare -a formula_services=({{ FORMULA_SERVICES }});
417 echo -e "\nInstalling all required salt formulas\n";
418 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
419 for formula_service in "${formula_services[@]}"; do
420 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
421 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
422 done;
423 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
424 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
425 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
426
427 cat << 'EOF' >> /etc/reclass/reclass-config.yml
428 storage_type: yaml_fs
429 pretty_print: True
430 output: yaml
431 inventory_base_uri: /srv/salt/reclass
432 EOF
433 node_name: {{ HOSTNAME_CFG01 }}
434 retry: {count: 1, delay: 1}
435 skip_fail: false
436
437- description: "*Workaround* remove all cfg01 nodes except {{ HOSTNAME_CFG01 }} to not depend on other clusters in 'reclass --top'"
438 cmd: |
439 # Remove all other nodes except {{ HOSTNAME_CFG01 }} to not rely on them for 'reclass --top'
440 find /srv/salt/reclass/nodes/ -type f -not -name {{ HOSTNAME_CFG01 }}.yml -delete
441 node_name: {{ HOSTNAME_CFG01 }}
442 retry: {count: 1, delay: 5}
443 skip_fail: false
444
445- description: Configure salt adoptors on cfg01
446 cmd: |
447 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
448 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
449 node_name: {{ HOSTNAME_CFG01 }}
450 retry: {count: 1, delay: 1}
451 skip_fail: false
452
453- description: Show reclass-salt --top for cfg01 node
454 cmd: reclass-salt --top
455 node_name: {{ HOSTNAME_CFG01 }}
456 retry: {count: 1, delay: 5}
457 skip_fail: false
458
459- description: Restart salt-master service
460 cmd: systemctl restart salt-master;
461 node_name: {{ HOSTNAME_CFG01 }}
462 retry: {count: 1, delay: 5}
463 skip_fail: false
464{%- endmacro %}
465
466
467{%- macro MACRO_INSTALL_SALT_MINIONS() %}
468{#######################################}
469{% for ssh in config.underlay.ssh %}
470- description: Configure salt-minion on {{ ssh['node_name'] }}
471 cmd: |
472 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
473 cat << "EOF" >> /etc/salt/minion.d/minion.conf
474 id: {{ ssh['node_name'] }}
475 master: {{ config.salt.salt_master_host }}
476 EOF
477 eatmydata apt-get install -y salt-minion;
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300478 service salt-minion restart; # For case if salt-minion was already installed
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300479 node_name: {{ ssh['node_name'] }}
480 retry: {count: 1, delay: 1}
481 skip_fail: false
482{% endfor %}
483
484
485- description: Accept salt keys from all the nodes
486 cmd: salt-key -A -y
487 node_name: {{ HOSTNAME_CFG01 }}
488 retry: {count: 1, delay: 5}
489 skip_fail: true
490{%- endmacro %}
491
492
493{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
494{##################################################}
495
496{# Prepare salt services and nodes settings #}
497
498- description: Run 'linux' formula on cfg01
499 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
500 node_name: {{ HOSTNAME_CFG01 }}
501 retry: {count: 3, delay: 5}
502 skip_fail: false
503
504- description: Run 'openssh' formula on cfg01
505 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300506 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300507 salt --hard-crash --state-output=mixed --state-verbose=False
508 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300509 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300510 node_name: {{ HOSTNAME_CFG01 }}
511 retry: {count: 3, delay: 5}
512 skip_fail: false
513
514- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
515 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
516 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
517 node_name: {{ HOSTNAME_CFG01 }}
518 retry: {count: 1, delay: 1}
519 skip_fail: false
520
521- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300522 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 +0300523 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300524 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300525 skip_fail: false
526
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400527{%- if SALT_FORMULAS_REFS != '' %}
528- description: Replace needed formulas to desired version
529 cmd: |
530 set -e;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400531 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
532 {% set formula = formula_set.split(':') %}
533 {% set formula_name = formula[0] %}
534 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300535 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400536 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
537 pushd {{ formula_dir }} &&
538 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
539 git checkout FETCH_HEAD &&
540 popd &&
541 if [ -d "{{ formula_dir }}" ]; then
542 echo "Going to replace packaged formula {{ formula_name }}" &&
543 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400544 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
545 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400546 else
547 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
548 fi
549 {%- endfor %}
550 node_name: {{ HOSTNAME_CFG01 }}
551 retry: {count: 1, delay: 10}
552 skip_fail: false
553{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300554
555- description: Refresh pillars on salt-master minion
556 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
557 node_name: {{ HOSTNAME_CFG01 }}
558 retry: {count: 1, delay: 5}
559 skip_fail: false
560
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300561- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300562 cmd: reclass-salt --top
563 node_name: {{ HOSTNAME_CFG01 }}
564 retry: {count: 1, delay: 5}
565 skip_fail: false
566
567- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300568 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 +0300569 node_name: {{ HOSTNAME_CFG01 }}
570 retry: {count: 1, delay: 5}
571 skip_fail: false
572
573- description: Configure linux on master
574 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
575 node_name: {{ HOSTNAME_CFG01 }}
576 retry: {count: 1, delay: 5}
577 skip_fail: false
578
579- description: Configure salt.minion on master
580 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
581 -C 'I@salt:master' state.sls salt.minion && sleep 10
582 node_name: {{ HOSTNAME_CFG01 }}
583 retry: {count: 3, delay: 10}
584 skip_fail: false
585
586- description: Run state 'salt' on master (for salt.api, etc)
587 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
588 -C 'I@salt:master' state.sls salt
589 node_name: {{ HOSTNAME_CFG01 }}
590 retry: {count: 3, delay: 10}
591 skip_fail: false
592{%- endmacro %}
593
594{%- macro MACRO_GENERATE_INVENTORY() %}
595{#####################################}
596- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
597 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
598 -C 'I@salt:master' state.sls reclass
599 node_name: {{ HOSTNAME_CFG01 }}
600 retry: {count: 1, delay: 5}
601 skip_fail: false
602
603- description: Refresh pillars on all minions
604 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
605 node_name: {{ HOSTNAME_CFG01 }}
606 retry: {count: 1, delay: 5}
607 skip_fail: false
608
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300609- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300610 cmd: |
611 set -e
612 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
613 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
614 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300615 node_name: {{ HOSTNAME_CFG01 }}
616 retry: {count: 1, delay: 5}
617 skip_fail: false
618
619- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300620 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300621 node_name: {{ HOSTNAME_CFG01 }}
622 retry: {count: 1, delay: 5}
623 skip_fail: false
624{%- endmacro %}
625
626
627{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
628{########################################}
629# Bootstrap all nodes
630- description: Configure linux on other nodes
631 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
632 node_name: {{ HOSTNAME_CFG01 }}
633 retry: {count: 5, delay: 10}
634 skip_fail: false
635
636- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300637 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 +0300638 salt --hard-crash --state-output=mixed --state-verbose=False
639 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
640 yes/' /etc/ssh/sshd_config && service ssh reload"
641 node_name: {{ HOSTNAME_CFG01 }}
642 retry: {count: 1, delay: 5}
643 skip_fail: false
644
645- description: Configure salt.minion on other nodes
646 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion &&
647 sleep 10
648 node_name: {{ HOSTNAME_CFG01 }}
649 retry: {count: 3, delay: 15}
650 skip_fail: false
651
652- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400653 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300654 node_name: {{ HOSTNAME_CFG01 }}
655 retry: {count: 3, delay: 15}
656 skip_fail: false
657
658- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400659 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300660 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400661 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300662 skip_fail: false
663
664- description: Configure ntp and rsyslog on nodes
665 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
666 node_name: {{ HOSTNAME_CFG01 }}
667 retry: {count: 1, delay: 10}
668 skip_fail: false
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200669{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300670
671
672{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
673{#########################################}
674
Oleksii Butenkof72f9d12017-10-18 13:10:04 +0300675#- description: '*Workaround 1/2* of the bug PROD-9576 to get bond0-connectivity *without* rebooting nodes'
676# cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False cmd.run
677# "mkdir -p /tmp/PROD-9576; cd /tmp/PROD-9576; git clone https://gerrit.mcp.mirantis.net/salt-formulas/linux; cd linux;
678# git fetch https://gerrit.mcp.mirantis.net/salt-formulas/linux refs/changes/54/2354/16 && git checkout FETCH_HEAD;
679# cp -f linux/network/interface.sls /srv/salt/env/prd/linux/network/;
680# cp -f linux/map.jinja /srv/salt/env/prd/linux/;"
681# node_name: {{ HOSTNAME_CFG01 }}
682# retry: {count: 1, delay: 5}
683# skip_fail: false
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300684
685- description: '*Workaround: Load bonding module before call state.linux'
686 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
687 node_name: {{ HOSTNAME_CFG01 }}
688 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +0300689 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300690
691- description: '*Workaround* install bridge-utils before running linux formula'
692 # The formula removes default route and then tries to install the package, fails.
693 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
694 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
695 node_name: {{ HOSTNAME_CFG01 }}
696 retry: {count: 1, delay: 5}
697 skip_fail: false
698
699{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400700
701{%- macro ADJUST_K8S_OPTS() %}
702{#########################################}
703
704- description: Set k8s deploy parameters
705 cmd: |
706 {% for k8s_opt, value in config.k8s_deploy.items() %}
707 {% if value|string() %}
708 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
709 {% endif %}
710 {% endfor %}
711 node_name: {{ HOSTNAME_CFG01 }}
712 retry: {count: 1, delay: 1}
713 skip_fail: false
714
715{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400716
717{%- macro REGISTER_COMPUTE_NODES() %}
718{#########################################}
719
720{% for ssh in config.underlay.ssh %}
721{% if ssh["node_name"].startswith("cmp") %}
722{% set node_hostname = ssh["node_name"].split('.')[0] %}
723- description: Register compute {{ ssh['node_name'] }}
724 cmd: |
725 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
726 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
727 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400728 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400729 export config_host={{ config.salt.salt_master_host }}
730 export node_domain={{ DOMAIN_NAME }}
731 export nodes_os="xenial"
732 export node_hostname={{ node_hostname }}
733 set -xe
734 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
735 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
736 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
737 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
738
739 # Add wrapper to apt-get to avoid race conditions
740 # with cron jobs running 'unattended-upgrades' script
741 aptget_wrapper() {
742 local apt_wrapper_timeout=300
743 local start_time=$(date '+%s')
744 local fin_time=$((start_time + apt_wrapper_timeout))
745 while true; do
746 if (( "$(date '+%s')" > fin_time )); then
747 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
748 fi
749 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
750 echo "Waiting while another apt/dpkg process releases locks ..."
751 sleep 30
752 continue
753 else
754 apt-get $@
755 break
756 fi
757 done
758 }
759
760 # Set default salt version
761 if [ -z "$saltversion" ]; then
762 saltversion="2016.3"
763 fi
764 echo "Using Salt version $saltversion"
765
766 echo "Preparing base OS ..."
767
768 case "$node_os" in
769 trusty)
770 # workaround for old cloud-init only configuring the first iface
771 iface_config_dir="/etc/network/interfaces"
772 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
773
774 for iface in $ifaces; do
775 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
776 done
777
778 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
779
780 # SUGGESTED UPDATE:
781 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
782 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
783 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
784 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
785 #install_salt_minion_pkg
786
787 # DEPRECATED:
788 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
789 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
790
791 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
792 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
793
794 aptget_wrapper clean
795 aptget_wrapper update
796 aptget_wrapper install -y salt-common
797 aptget_wrapper install -y salt-minion
798 ;;
799 xenial)
800
801 # workaround for new cloud-init setting all interfaces statically
802 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
803
804 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
805
806 # SUGGESTED UPDATE:
807 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
808 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
809 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
810 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
811 #install_salt_minion_pkg
812
813 # DEPRECATED:
814 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
815 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
816
817 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
818 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
819
820 aptget_wrapper clean
821 aptget_wrapper update
822 aptget_wrapper install -y salt-minion
823 ;;
824 rhel|centos|centos7|centos7|rhel6|rhel7)
825 yum install -y git
826 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
827 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
828 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
829 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
830 install_salt_minion_pkg
831 ;;
832 *)
833 msg="OS '$node_os' is not supported."
834 esac
835
836 echo "Configuring Salt minion ..."
837 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
838 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
839
840 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
841
842 sleep 1
843
844 echo "Classifying node ..."
845 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
846 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
847 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
848 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
849 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
850 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
851
852 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
853 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
854 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
855 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
856 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
857
858 if [ "$node_network05_iface" != "" ]; then
859 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
860 fi
861
862 # find more parameters (every env starting param_)
863 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
864 if [ "$more_params" != "" ]; then
865 echo "Additional params: $more_params"
866 more_params=", $more_params"
867 fi
868
869 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}}"
870
871 sleep 5
872
873 salt-call saltutil.sync_all
874 salt-call mine.flush
875 salt-call mine.update
876 node_name: {{ ssh['node_name'] }}
877 retry: {count: 1, delay: 1}
878 skip_fail: false
879{%- endif %}
880{%- endfor %}
881
882- description: Refresh pillars on all minions
883 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
884 node_name: {{ HOSTNAME_CFG01 }}
885 retry: {count: 1, delay: 5}
886 skip_fail: false
887
888- description: Sync all salt resources
889 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
890 node_name: {{ HOSTNAME_CFG01 }}
891 retry: {count: 1, delay: 5}
892 skip_fail: false
893
sgudz160b7302017-12-22 17:01:10 +0200894{%- endmacro %}