blob: 5785efbc5f53f202da7b0fd60a6d879ebca4ec27 [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') %}
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +03004{% set JENKINS_PIPELINE_BRANCH = os_env('JENKINS_PIPELINE_BRANCH','') %}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02005{% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %}
6{# 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 #}
7{% set SALT_MODELS_REF_CHANGE = os_env('SALT_MODELS_REF_CHANGE', '') %}
8{# Pin to a specified commit in salt-models/reclass-system #}
Dennis Dmitriev3d0ed0a2018-11-23 11:02:52 +00009{% set SALT_MODELS_SYSTEM_REPOSITORY = os_env('SALT_MODELS_SYSTEM_REPOSITORY','https://gerrit.mcp.mirantis.com/salt-models/reclass-system') %}
10{% set SALT_MODELS_SYSTEM_COMMIT = os_env('SALT_MODELS_SYSTEM_COMMIT','') %}
11{% set SALT_MODELS_SYSTEM_REF_CHANGE = os_env('SALT_MODELS_SYSTEM_REF_CHANGE','') %}
12{% set SALT_MODELS_SYSTEM_TAG = os_env('SALT_MODELS_SYSTEM_TAG','') %}
Dennis Dmitriev06979442018-10-24 18:53:49 +030013{% set COOKIECUTTER_TEMPLATES_REPOSITORY_USER = os_env('COOKIECUTTER_TEMPLATES_REPOSITORY_USER','mcp-gerrit') %}
14{% set COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH = os_env('COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH','') %}
15{% set COOKIECUTTER_TEMPLATES_REPOSITORY = os_env('COOKIECUTTER_TEMPLATES_REPOSITORY','ssh://' + COOKIECUTTER_TEMPLATES_REPOSITORY_USER +'@gerrit.mcp.mirantis.com:29418/mk/cookiecutter-templates') %}
sgudz4d816eb2017-11-13 11:58:05 +020016{% set COOKIECUTTER_REF_CHANGE = os_env('COOKIECUTTER_REF_CHANGE','') %}
Tatyana Leontovich819a6c82018-06-04 12:05:16 +030017{% set COOKIECUTTER_TAG = os_env('COOKIECUTTER_TAG','') %}
sgudza399dc72018-01-18 17:13:48 +020018{% set COOKIECUTTER_TEMPLATE_COMMIT = os_env('COOKIECUTTER_TEMPLATE_COMMIT','') %}
Vladimir Khlyunevf337c902018-12-06 12:29:24 +040019{% set ENVIRONMENT_TEMPLATE_COMMIT = os_env('ENVIRONMENT_TEMPLATE_COMMIT','') %}
sgudzcced67d2017-10-11 15:56:09 +030020{% set ENVIRONMENT_TEMPLATE_REF_CHANGE = os_env('ENVIRONMENT_TEMPLATE_REF_CHANGE','') %}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +030021# Currently we support 2 salt version that can be set over bellow var
Tatyana Leontovich14e201d2018-07-05 13:28:54 +030022{% set SALT_VERSION = os_env('SALT_VERSION','2017.7') %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +030023{% set REPOSITORY_SUITE = os_env('REPOSITORY_SUITE', 'testing') %}
Tatyana Leontovich3fb53412019-05-24 00:46:12 +030024{% set UPDATE_REPO_CUSTOM_TAG = os_env('UPDATE_REPO_CUSTOM_TAG', '') %}
25{% set UPDATE_VERSION = os_env('UPDATE_VERSION', 'proposed') %}
Dennis Dmitrievd9168b52018-12-19 18:53:52 +020026{# set FORMULA_REPOSITORY = os_env('FORMULA_REPOSITORY', 'deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME} ' + REPOSITORY_SUITE + ' salt extra') #}
obutenkob6006352018-12-20 10:46:44 +020027{% set FORMULA_REPOSITORY = os_env('FORMULA_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/salt-formulas"+"/${DISTRIB_CODENAME} ${DISTRIB_CODENAME} main") %}
Tatyana Leontovich3fb53412019-05-24 00:46:12 +030028{% set UPDATE_FORMULA_REPOSITORY = os_env('UPDATE_FORMULA_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/update/" + UPDATE_VERSION + "/salt-formulas"+"/${DISTRIB_CODENAME} ${DISTRIB_CODENAME} main") %}
Dennis Dmitrievd9168b52018-12-19 18:53:52 +020029{# set FORMULA_GPG = os_env('FORMULA_GPG', 'http://apt.mirantis.com/public.gpg') #}
obutenkob6006352018-12-20 10:46:44 +020030{% set FORMULA_GPG = os_env('FORMULA_GPG', "http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/salt-formulas/xenial/archive-salt-formulas.key") %}
Dennis Dmitrievd9168b52018-12-19 18:53:52 +020031{# set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME}/salt/2016.3 " + REPOSITORY_SUITE + " main") #}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +030032# Note repo is changed so new one looks like defined bellow
33{% set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE+ "/saltstack-" + SALT_VERSION+ "/${DISTRIB_CODENAME} ${DISTRIB_CODENAME} main") %}
Dennis Dmitrievd9168b52018-12-19 18:53:52 +020034{# set SALT_GPG = os_env('SALT_GPG', 'http://apt.mirantis.com/public.gpg') #}
obutenkob6006352018-12-20 10:46:44 +020035{% set SALT_GPG = os_env('SALT_GPG', "http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/salt-formulas/xenial/archive-salt-formulas.key") %}
Dennis Dmitrievcf777802018-02-14 18:09:55 +020036{% set UBUNTU_REPOSITORY = os_env('UBUNTU_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME} main restricted universe") %}
37{% set UBUNTU_UPDATES_REPOSITORY = os_env('UBUNTU_UPDATES_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME}-updates main restricted universe") %}
38{% set UBUNTU_SECURITY_REPOSITORY = os_env('UBUNTU_SECURITY_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME}-security main restricted universe") %}
Dennis Dmitriev9a532a52018-05-07 13:55:27 +030039{% set UBUNTU_KEY_SERVER = os_env('UBUNTU_KEY_SERVER', 'keyserver.ubuntu.com') %}
Tatyana Leontovich908ab932018-04-27 01:25:09 +030040{% set UBUNTU_KEY_ID = os_env('UBUNTU_KEY_ID', '0E08A149DE57BFBE') %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +030041
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020042{# Address pools for reclass cluster model are taken in the following order:
43 # 1. environment variables,
44 # 2. config.underlay.address_pools based on fuel-devops address pools
45 # (see generated '.ini' file after underlay is created),
46 # 3. defaults #}
47{% set address_pools = config.underlay.address_pools %}
48{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
49{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
50{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
51{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
52{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
53{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
54{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
55{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
56
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040057{# Format for formula replacement:
58 # space separated string:
59 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
60
61{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
Tatyana Leontovich1c101312018-04-18 20:33:08 +030062{% set TEMPEST_PATTERN = os_env('TEMPEST_PATTERN', 'tempest') %}
Tatyana Leontovich69700712018-04-23 12:26:57 +030063{% set EXCLUDE_TEST_ARGS = os_env('EXCLUDE_TEST_ARGS', '') %}
Dennis Dmitriev0f272312018-10-01 13:29:40 +030064{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.com/salt-formulas') %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040065
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040066# Needed for using different models in different templates
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020067{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040068
Dennis Dmitriev492813e2017-08-09 15:08:58 +030069
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020070{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
71{#####################################################}
72
73- description: 'Configure key on nodes and install packages'
74 cmd: |
75 rm -rf trusted* ;
76 rm -rf /etc/apt/sources.list ;
Dennis Dmitrievcf777802018-02-14 18:09:55 +020077 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020078 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
79 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
80 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +030081 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020082 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
83 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
84 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
Dennis Dmitrievf4e6efc2018-03-26 06:15:10 -050085 eatmydata apt-get clean;
86 apt-get update;
Dennis Dmitriev01d5e372018-03-15 23:29:29 +020087 sync;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020088 node_name: {{ NODE_NAME }}
89 retry: {count: 1, delay: 5}
90 skip_fail: false
91
92{%- endmacro %}
93
94
Tatyana Leontovich3fb53412019-05-24 00:46:12 +030095{%- macro MACRO_INSTALL_FORMULAS_FROM_UPDATE() %}
96{#####################################################}
97
98- description: 'Configure key on nodes and install packages'
99 cmd: |
100 rm -rf trusted* ;
101 rm -rf /etc/apt/sources.list ;
102 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
103 echo "{{ UPDATE_FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_update_salt.list;
104 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
105 eatmydata apt-get clean;
106 apt-get update;
107 sync;
108 node_name: {{ HOSTNAME_CFG01 }}
109 retry: {count: 1, delay: 5}
110 skip_fail: false
111
112{%- endmacro %}
113
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300114{%- macro MACRO_INSTALL_SALT_MASTER() %}
115{######################################}
116- description: Installing salt master on cfg01
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200117 cmd: |
118 which wget >/dev/null || (apt-get update; apt-get install -y wget);
119 # Configure ubuntu and salt repositories
120 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
121 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
122 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
123 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
124
125 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
126 wget -O - {{ FORMULA_GPG }} | apt-key add -;
127 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300128 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
129
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200130
131 apt-get clean
132 apt-get update
133
134 # Install salt-master and reclass
135 eatmydata apt-get install -y --allow-unauthenticated reclass salt-master
136 # Install common packages
Dennis Dmitrievf88fc7d2018-02-20 15:40:08 +0200137 eatmydata apt-get install -y python-pip git curl at tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200138 sync;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300139 node_name: {{ HOSTNAME_CFG01 }}
140 retry: {count: 1, delay: 1}
141 skip_fail: false
142
Dennis Dmitrievda9be462018-01-24 21:20:09 +0200143- description: Remove any existing minion keys
144 cmd: salt-key -y -D || true
145 node_name: {{ HOSTNAME_CFG01 }}
146 retry: {count: 1, delay: 1}
147 skip_fail: false
148
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300149- description: Configure salt-master on cfg01
150 cmd: |
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200151 cat << 'EOF' > /etc/salt/master.d/master.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300152 file_roots:
153 base:
154 - /usr/share/salt-formulas/env
155 pillar_opts: False
156 open_mode: True
157 reclass: &reclass
158 storage_type: yaml_fs
159 inventory_base_uri: /srv/salt/reclass
160 ext_pillar:
161 - reclass: *reclass
162 master_tops:
163 reclass: *reclass
164 EOF
165 node_name: {{ HOSTNAME_CFG01 }}
166 retry: {count: 1, delay: 1}
167 skip_fail: false
168
169- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300170 cmd: |
171 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200172 #touch /root/.git_trusted_certs.pem;
173 #for server in github.com; do \
174 # openssl s_client -showcerts -connect $server:443 </dev/null \
175 # | openssl x509 -outform PEM \
176 # >> /root/.git_trusted_certs.pem;
177 #done;
178 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
179 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
180 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300181 node_name: {{ HOSTNAME_CFG01 }}
182 retry: {count: 1, delay: 1}
183 skip_fail: false
184{%- endmacro %}
185
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200186
187{%- macro MACRO_CONFIG_DAY01_SALT_MASTER() %}
188{######################################}
189
190- description: Remove /etc/update-motd.d/52-info
191 cmd: rm -vf /etc/update-motd.d/52-info
192 node_name: {{ HOSTNAME_CFG01 }}
193 retry: {count: 1, delay: 10}
194 skip_fail: false
195
196- description: Set up static interface config
197 cmd: |
198 kill $(pidof /sbin/dhclient) || /bin/true
199 cat << 'EOF' > /etc/network/interfaces
200 # This file describes the network interfaces available on your system
201 # and how to activate them. For more information, see interfaces(5).
202
203 # The loopback network interface
204 auto lo
205 iface lo inet loopback
206
207 # The primary network interface
208 auto ens3
209 iface ens3 inet static
210 address {{ IPV4_NET_ADMIN_PREFIX }}.90
211 netmask 255.255.255.0
212 gateway {{ IPV4_NET_ADMIN_PREFIX }}.1
213 EOF
214 node_name: {{ HOSTNAME_CFG01 }}
215 retry: {count: 1, delay: 10}
216 skip_fail: false
217
218- description: Install common packages on cfg01
219 cmd: eatmydata apt-get update && apt-get install -y python-pip git curl at tmux byobu iputils-ping traceroute htop tree wget jq ntpdate
220 node_name: {{ HOSTNAME_CFG01 }}
221 retry: {count: 1, delay: 1}
222 skip_fail: false
223
224- description: Remove any existing minion keys
225 cmd: salt-key -y -D || true
226 node_name: {{ HOSTNAME_CFG01 }}
227 retry: {count: 1, delay: 1}
228 skip_fail: false
229
230- description: Configure GIT settings and certificates
231 cmd: |
232 set -e;
233 #touch /root/.git_trusted_certs.pem;
234 #for server in github.com; do \
235 # openssl s_client -showcerts -connect $server:443 </dev/null \
236 # | openssl x509 -outform PEM \
237 # >> /root/.git_trusted_certs.pem;
238 #done;
239 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
240 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
241 HOME=/root git config --global user.name "MCP Integration QA";
242 node_name: {{ HOSTNAME_CFG01 }}
243 retry: {count: 1, delay: 1}
244 skip_fail: false
245{%- endmacro %}
246
247
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300248{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false, WITH_MAAS=false) %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300249{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300250{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
251
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300252- description: Clone reclass models with submodules
253 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300254 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200255 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200256 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200257
258 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
259 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 +0200260 rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200261
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200262 pushd /srv/salt/reclass;
263 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
264 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200265 {%- if SALT_MODELS_REF_CHANGE != '' %}
266 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200267 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200268 {%- endfor %}
269 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200270 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200271 {%- endif %}
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300272
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300273 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300274 pushd classes/system/ && \
275 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200276 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300277 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200278 popd;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300279 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
280 pushd classes/system/;
281 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
282 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300283 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
284 pushd classes/system/;
285 git fetch --all --tags --prune
286 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
287 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200288 {%- endif %}
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300289
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200290 popd;
291 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300292 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200293
294 # Replace firstly to an intermediate value to avoid intersection between
295 # already replaced and replacing networks.
296 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
297 # 192.168.10 -> 10.16.0 (generated network for admin)
298 # 10.16.0 -> <external network>
299 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300300 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200301 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10/==IPV4_NET_ADMIN_PREFIX==/g' {} +
302 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10/==IPV4_NET_CONTROL_PREFIX==/g' {} +
303 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0/==IPV4_NET_TENANT_PREFIX==/g' {} +
304 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Tatyana Leontovich26756912018-06-06 20:11:05 +0300305 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.60\.0/==IPV4_NET_CONTROL_PREFIX==/g' {} +
306 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.70\.0/==IPV4_NET_ADMIN_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200307
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200308 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
309 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
310 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
311 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 +0200312
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300313 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
Victor Ryzhenkine784bbf2018-12-21 03:58:00 +0400314 find ${REPLACE_DIRS} -type f -exec sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200315
Tatyana Leontovicha4a96b22018-04-25 14:30:24 +0300316 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300317 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300318 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 +0300319 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 +0300320 {%- endif %}
321
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200322 # Override some context parameters
323 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
324 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
325 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
326
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200327 # Create the cfg01 inventory file or use existing
328 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
329 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300330 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400331 - cluster.{{ CLUSTER_NAME }}.infra.config
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300332 {%- if WITH_MAAS %}
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200333 - cluster.{{ CLUSTER_NAME }}.infra.maas
334 - cluster.{{ CLUSTER_NAME }}.infra.maas-machines
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300335 {%- endif %}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300336 parameters:
337 _param:
338 linux_system_codename: xenial
339 reclass_data_revision: master
340 linux:
341 system:
342 name: cfg01
343 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200344 reclass:
345 storage:
346 data_source:
347 engine: local
348 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300349
350 # Show the changes to the console
351 cd /srv/salt/reclass/; git diff
352 node_name: {{ HOSTNAME_CFG01 }}
353 retry: {count: 1, delay: 1}
354 skip_fail: false
355{%- endmacro %}
356
Dmitry Tyzhnenkofcb4dab2019-03-05 20:11:59 +0200357{%- macro MACRO_UPLOAD_AND_IMPORT_GPG_ENCRYPTION_KEY() %}
358{%- set KEY_FILE_NAME = 'encryption-key.asc' %}
359- description: "Upload gpg encruption key"
360 upload:
361 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
362 local_filename: {{ KEY_FILE_NAME }}
363 remote_path: /root/
364 node_name: {{ HOSTNAME_CFG01 }}
365
366- description: Import encryption key
367 cmd: |
Tatyana Leontovich1192aa42019-03-25 14:11:27 +0200368 set -ex;
369 mkdir -p /etc/salt/gpgkeys
370 chmod 0700 /etc/salt/gpgkeys
371 export GNUPGHOME=/etc/salt/gpgkeys
Dmitry Tyzhnenkofcb4dab2019-03-05 20:11:59 +0200372 gpg --import {{ KEY_FILE_NAME }}
373 gpg --list-keys
374 node_name: {{ HOSTNAME_CFG01 }}
375 retry: {count: 1, delay: 1}
376 skip_fail: false
377
378- description: Put encryption key to reclass folder
379 cmd: |
380 set -e;
381 set -x;
382 mkdir -p /srv/salt/reclass
383 cp /root/{{ KEY_FILE_NAME }} /srv/salt/reclass/
384 node_name: {{ HOSTNAME_CFG01 }}
385 retry: {count: 1, delay: 1}
386 skip_fail: false
387
388{%- endmacro %}
389
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300390
sgudz160b7302017-12-22 17:01:10 +0200391{%- 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 +0300392{###################################################################}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300393{%- set CLUSTER_CONTEXT_PATH = '/root/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200394- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300395 upload:
396 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
397 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300398 remote_path: /root/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300399 node_name: {{ HOSTNAME_CFG01 }}
400
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300401- description: "Show options enabled in the context file for model generation"
402 cmd: |
403 echo "===== Options enabled in the context for generation the model {{ LAB_CONFIG_NAME }} ====="
404 fgrep "True" {{ CLUSTER_CONTEXT_PATH }}
405 echo "===== Sources for model generation ====="
406 echo "# mcp_version: {{ REPOSITORY_SUITE }}"
407 echo "COOKIECUTTER_TEMPLATES_REPOSITORY={{ COOKIECUTTER_TEMPLATES_REPOSITORY }}"
408 {%- if CLUSTER_PRODUCT_MODELS != '' %}
409 echo "CLUSTER_PRODUCT_MODELS={{ CLUSTER_PRODUCT_MODELS }}"
410 {%- endif %}
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300411 {%- if COOKIECUTTER_REF_CHANGE != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300412 echo "COOKIECUTTER_REF_CHANGE={{ COOKIECUTTER_REF_CHANGE }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300413 {%- elif COOKIECUTTER_TEMPLATE_COMMIT != '' %}
414 echo "COOKIECUTTER_TEMPLATE_COMMIT={{ COOKIECUTTER_TEMPLATE_COMMIT }}"
Dennis Dmitriev713dce22018-07-03 11:47:46 +0300415 {%- elif COOKIECUTTER_TAG != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300416 echo "COOKIECUTTER_TAG={{ COOKIECUTTER_TAG }}"
417 {%- endif %}
418 echo "SALT_MODELS_SYSTEM_REPOSITORY={{ SALT_MODELS_SYSTEM_REPOSITORY }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300419 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300420 echo "SALT_MODELS_SYSTEM_REF_CHANGE={{ SALT_MODELS_SYSTEM_REF_CHANGE }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300421 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
422 echo "SALT_MODELS_SYSTEM_COMMIT={{ SALT_MODELS_SYSTEM_COMMIT }}"
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300423 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
424 echo "SALT_MODELS_SYSTEM_TAG={{ SALT_MODELS_SYSTEM_TAG }}"
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300425 {%- endif %}
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +0300426 {%- if JENKINS_PIPELINE_BRANCH != '' %}
427 echo "JENKINS_PIPELINE_BRANCH={{ JENKINS_PIPELINE_BRANCH }}"
428 {%- endif %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300429 echo "======================================="
430 node_name: {{ HOSTNAME_CFG01 }}
431 retry: {count: 1, delay: 1}
432 skip_fail: false
433
Dennis Dmitriev06979442018-10-24 18:53:49 +0300434- description: "Upload {{ COOKIECUTTER_TEMPLATES_REPOSITORY_USER }} key"
435 upload:
436 local_path: {{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | dirname }}/
437 local_filename: {{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
438 remote_path: /tmp/
439 node_name: {{ HOSTNAME_CFG01 }}
440
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300441- description: Create cluster model from cookiecutter templates
442 cmd: |
443 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300444 set -x;
Tatyana Leontovich1ef60952018-12-19 00:36:50 +0200445 sudo apt-get install virtualenv -y
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300446 sudo apt-get install python-setuptools -y
Dennis Dmitrievb4b74032018-12-18 21:53:23 +0200447
448 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
449 . /root/venv-reclass-tools/bin/activate;
450 pip install -U pip
451
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300452 pip install cookiecutter
Dennis Dmitriev06979442018-10-24 18:53:49 +0300453
454 chmod 0600 /tmp/{{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
455 eval $(ssh-agent)
456 ssh-add /tmp/{{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
Hanna Arhipova894a7682021-09-27 14:11:53 +0300457
458 git config --global user.name {{ HOSTNAME_CFG01 }}
459 git config --global user.email {{ HOSTNAME_CFG01 }}@example.com
460
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300461 export GIT_SSL_NO_VERIFY=true; git clone {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} /root/cookiecutter-templates
sgudz4d816eb2017-11-13 11:58:05 +0200462
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300463 {%- if COOKIECUTTER_REF_CHANGE != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300464 pushd /root/cookiecutter-templates
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300465 git fetch {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
sgudz4d816eb2017-11-13 11:58:05 +0200466 popd
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300467 {%- elif COOKIECUTTER_TEMPLATE_COMMIT != '' %}
468 pushd /root/cookiecutter-templates
469 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
470 popd
Dennis Dmitriev713dce22018-07-03 11:47:46 +0300471 {%- elif COOKIECUTTER_TAG != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300472 pushd /root/cookiecutter-templates
Tatyana Leontovich819a6c82018-06-04 12:05:16 +0300473 git fetch --all --tags --prune
474 git checkout tags/{{ COOKIECUTTER_TAG }}
475 popd
476 {%- endif %}
477
Dennis Dmitrievddcea2f2018-12-18 21:21:11 +0200478 if [ -f /root/cookiecutter-templates/requirements.txt ]; then
479 pip install -r /root/cookiecutter-templates/requirements.txt
480 fi
481
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300482 mkdir -p /srv/salt/reclass/classes/cluster/
483 mkdir -p /srv/salt/reclass/classes/system/
484 mkdir -p /srv/salt/reclass/classes/service/
485 mkdir -p /srv/salt/reclass/nodes/_generated
486
487 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200488 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
489 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200490 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +0300491 {%- if JENKINS_PIPELINE_BRANCH != '' %}
Hanna Arhipovac2965a42020-01-21 12:27:33 +0200492 # Escape / with \/
Dmitriy Kruglov402ef3b2020-01-29 23:52:12 +0100493 escaped_branch=$(echo {{ JENKINS_PIPELINE_BRANCH }} | sed s'/\//\\\//g')
494 sed -i "s/jenkins_pipelines_branch:.*/jenkins_pipelines_branch: '$escaped_branch'/g" {{ CLUSTER_CONTEXT_PATH }}
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +0300495 {%- endif %}
sgudz8c888ec2017-10-02 15:29:23 +0300496 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200497 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300498 {%- endif %}
499 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200500 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300501 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300502
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300503 # Replace firstly to an intermediate value to avoid intersection between
504 # already replaced and replacing networks.
505 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
506 # 192.168.10 -> 10.16.0 (generated network for admin)
507 # 10.16.0 -> <external network>
508 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300509 export REPLACE_DIRS="{{ CLUSTER_CONTEXT_PATH }} /root/cookiecutter-templates"
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300510 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
511 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
512 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
513 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300514
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300515 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
516 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
517 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
518 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {} +
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300519
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300520 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /root/cookiecutter-templates/cluster_product/)' %}
Dmitry Tyzhnenkofcb4dab2019-03-05 20:11:59 +0200521 mkdir -p /tmp/output /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/
Tatyana Leontovich1192aa42019-03-25 14:11:27 +0200522 # Allow to use encryption keys
523 export GNUPGHOME=/etc/salt/gpgkeys
sgudz160b7302017-12-22 17:01:10 +0200524 for item in {{ items }}; do
Dmitry Tyzhnenkofcb4dab2019-03-05 20:11:59 +0200525 [ "$item" = "stacklight2" ] && continue;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300526 python /root/cookiecutter-templates/generate.py \
527 --template /root/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300528 --config-file {{ CLUSTER_CONTEXT_PATH }} \
Dmitry Tyzhnenkofcb4dab2019-03-05 20:11:59 +0200529 --output-dir /tmp/output/$item/;
530 mv -v /tmp/output/$item/{{ CLUSTER_NAME }}/$item /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300531 done
532
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300533 export GIT_SSL_NO_VERIFY=true; git clone {{ SALT_MODELS_SYSTEM_REPOSITORY }} /srv/salt/reclass/classes/system/
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300534
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200535 # Create the cfg01 inventory file or use existing
536 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
537 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300538 classes:
539 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200540 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300541 EOF
542
543 node_name: {{ HOSTNAME_CFG01 }}
544 retry: {count: 1, delay: 1}
545 skip_fail: false
546
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300547- description: Modify generated model and reclass-system if necessary
548 cmd: |
549 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300550 set -x;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300551 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300552 pushd /srv/salt/reclass/classes/system/ && \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300553 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300554 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300555 {%- endfor %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300556 popd;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300557 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
558 pushd /srv/salt/reclass/classes/system/
559 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
560 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300561 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
562 pushd /srv/salt/reclass/classes/system/
563 git fetch --all --tags --prune
564 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
565 popd;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300566 {%- endif %}
567
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300568 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200569 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300570 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
571 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
572 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
573 {%- endif %}
574
575 node_name: {{ HOSTNAME_CFG01 }}
576 retry: {count: 1, delay: 1}
577 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +0300578
579- description: Restart salt-api
580 cmd: |
581 set -e;
582 systemctl restart salt-api
583
584 node_name: {{ HOSTNAME_CFG01 }}
585 retry: {count: 1, delay: 1}
586 skip_fail: false
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300587{%- endmacro %}
588
589
Taras Khlivnyakb68630b2021-04-26 23:24:56 +0300590{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL(KNOWN_HOST_AUTOPOPULATION=true) %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300591{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300592
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200593- description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300594 cmd: |
595 set -e;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300596 mkdir -p /root/environment/;
Hanna Arhipova5173aad2019-11-11 12:42:31 +0200597 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.com/mcp/tcp-qa-environment-template /root/environment/environment_template
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300598
Vladimir Khlyunevf337c902018-12-06 12:29:24 +0400599 {%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300600 pushd /root/environment/environment_template &&
Hanna Arhipovae6357222020-01-08 19:55:27 +0200601 git fetch https://gerrit.mcp.mirantis.com/mcp/tcp-qa-environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
sgudzcced67d2017-10-11 15:56:09 +0300602 git checkout FETCH_HEAD &&
603 popd
Vladimir Khlyunevf337c902018-12-06 12:29:24 +0400604 {%- elif ENVIRONMENT_TEMPLATE_COMMIT != '' %}
605 pushd /root/environment/environment_template
606 git checkout {{ ENVIRONMENT_TEMPLATE_COMMIT }}
607 popd
608 {%- endif %}
609
sgudzcced67d2017-10-11 15:56:09 +0300610 node_name: {{ HOSTNAME_CFG01 }}
611 skip_fail: false
sgudzcced67d2017-10-11 15:56:09 +0300612
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300613{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200614- description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300615 upload:
616 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
617 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300618 remote_path: /root/environment/
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300619 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300620{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300621
Dennis Dmitriev1ddf6472018-11-25 22:30:12 +0200622- description: "Replace template addresses to actual environment addresses"
623 cmd: |
624 set -ex;
625 # Replace firstly to an intermediate value to avoid intersection between
626 # already replaced and replacing networks.
627 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
628 # 192.168.10 -> 10.16.0 (generated network for admin)
629 # 10.16.0 -> <external network>
630 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
631 export REPLACE_DIRS="/root/environment/"
632 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
633 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
634 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
635 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
636
637 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
638 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
639 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
640 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {} +
641 node_name: {{ HOSTNAME_CFG01 }}
642 retry: {count: 1, delay: 5}
643 skip_fail: false
644
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300645- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
646 cmd: |
647 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300648 set -x;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300649 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200650 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
651 . /root/venv-reclass-tools/bin/activate;
Hanna Arhipovad33353e2021-02-15 23:14:51 +0200652 pip install git+https://gerrit.mcp.mirantis.com/mcp/tcp-qa-reclass-tools;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300653 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
654 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
655 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
656
Dennis Dmitriev6368f082018-02-23 13:30:30 -0500657 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
658 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
659 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300660 fi;
661
662 node_name: {{ HOSTNAME_CFG01 }}
663 retry: {count: 1, delay: 5}
664 skip_fail: false
665
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200666- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300667 cmd: |
668 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200669 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 +0300670
671 node_name: {{ HOSTNAME_CFG01 }}
672 retry: {count: 1, delay: 5}
673 skip_fail: false
674
675- description: "[EXPERIMENTAL] Create environment model for virtual environment"
676 cmd: |
677 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300678 set -x;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200679 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300680 reclass-tools render --template-dir /root/environment/environment_template/ \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300681 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300682 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /root/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300683 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
684 node_name: {{ HOSTNAME_CFG01 }}
685 retry: {count: 1, delay: 5}
686 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300687
Taras Khlivnyakb68630b2021-04-26 23:24:56 +0300688- description: "[EXPERIMENTAL] Disable known_host_autopopulation if its not enabled"
689 cmd: |
690 {%- if not KNOWN_HOST_AUTOPOPULATION %}
691 set -e;
692 set -x;
693 . /root/venv-reclass-tools/bin/activate;
694 reclass-tools add-bool-key parameters.reclass.storage.node.infra_config_node01.parameters.openssh.client.known_hosts_autopopulation false /srv/salt/reclass/classes/environment/{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}/init.yml
695 {%- endif %}
696 node_name: {{ HOSTNAME_CFG01 }}
697 retry: {count: 1, delay: 5}
698 skip_fail: false
699
sgudz8c888ec2017-10-02 15:29:23 +0300700- description: Modify generated model and reclass-system
701 cmd: |
702 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
703 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
Victor Ryzhenkine784bbf2018-12-21 03:58:00 +0400704 find ${REPLACE_DIRS} -type f -exec sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {} +
sgudz8c888ec2017-10-02 15:29:23 +0300705 node_name: {{ HOSTNAME_CFG01 }}
706 retry: {count: 1, delay: 1}
707 skip_fail: false
708
sgudzb7953382019-02-18 17:59:30 +0200709{%- if UPDATE_REPO_CUSTOM_TAG != '' %}
Hanna Arhipovaaad914c2020-04-13 17:10:20 +0300710- description: "[EXPERIMENTAL] Change update repos tag according to defined in job"
sgudzb7953382019-02-18 17:59:30 +0200711 cmd: |
712 . /root/venv-reclass-tools/bin/activate;
713 reclass-tools add-key parameters._param.linux_system_repo_update_url 'http://mirror.mirantis.com/update/{{ UPDATE_REPO_CUSTOM_TAG }}/' /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/openstack/init.yml;
sgudzb7953382019-02-18 17:59:30 +0200714 node_name: {{ HOSTNAME_CFG01 }}
715 retry: {count: 1, delay: 5}
716 skip_fail: false
717{%- endif %}
718
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300719{%- endmacro %}
720
721
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300722{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
723{#######################################################}
724- description: Configure reclass
725 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300726 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300727 set -x;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300728 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300729 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200730 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200731 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
732 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300733 apt-get clean; apt-get update;
734 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
735 declare -a formula_services=({{ FORMULA_SERVICES }});
736 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200737 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300738 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300739 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
740 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
741 done;
742 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
743 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
744 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
745
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200746 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300747 storage_type: yaml_fs
748 pretty_print: True
749 output: yaml
750 inventory_base_uri: /srv/salt/reclass
751 EOF
752 node_name: {{ HOSTNAME_CFG01 }}
753 retry: {count: 1, delay: 1}
754 skip_fail: false
755
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200756- description: "*Workaround* remove all cfg01 nodes except cfg01.{{ DOMAIN_NAME }} to not depend on other clusters in 'reclass --top'"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300757 cmd: |
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200758 # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top'
759 find /srv/salt/reclass/nodes/ -type f -not -name cfg01.{{ DOMAIN_NAME }}.yml -delete
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300760 node_name: {{ HOSTNAME_CFG01 }}
761 retry: {count: 1, delay: 5}
762 skip_fail: false
763
764- description: Configure salt adoptors on cfg01
765 cmd: |
766 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
767 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
768 node_name: {{ HOSTNAME_CFG01 }}
769 retry: {count: 1, delay: 1}
770 skip_fail: false
771
772- description: Show reclass-salt --top for cfg01 node
773 cmd: reclass-salt --top
774 node_name: {{ HOSTNAME_CFG01 }}
775 retry: {count: 1, delay: 5}
776 skip_fail: false
777
778- description: Restart salt-master service
ibumarskov712a6872018-04-25 09:22:15 +0400779 cmd: service salt-master restart;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300780 node_name: {{ HOSTNAME_CFG01 }}
781 retry: {count: 1, delay: 5}
782 skip_fail: false
783{%- endmacro %}
784
785
786{%- macro MACRO_INSTALL_SALT_MINIONS() %}
787{#######################################}
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200788{%- for ssh in config.underlay.ssh %}
789 {%- set salt_roles = [] %}
790 {%- for role in ssh['roles'] %}
791 {%- if role in config.salt_deploy.salt_roles %}
792 {%- set _ = salt_roles.append(role) %}
793 {%- endif %}
794 {%- endfor %}
795
796 {%- if salt_roles %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300797- description: Configure salt-minion on {{ ssh['node_name'] }}
798 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300799 set -ex;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300800 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitriev3fe24dd2018-07-20 18:38:57 +0300801 cat << EOF > /etc/salt/minion.d/minion.conf
802 id: $(hostname -s).{{ DOMAIN_NAME }}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300803 master: {{ config.salt.salt_master_host }}
804 EOF
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200805
806 # Configure ubuntu and salt repositories
807 which wget >/dev/null || (apt-get update; apt-get install -y wget);
808
809 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
810 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
811 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
812 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
813
814 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300815 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
816
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200817
818 apt-get clean
819 apt-get update
820
821 # Install salt-minion
Tatyana Leontovich47708552018-12-19 16:36:09 +0200822 apt-get install eatmydata -y;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300823 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200824 # Install common packages
825 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200826 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200827 # Restart salt-minion if it was already installed
828 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300829 node_name: {{ ssh['node_name'] }}
Hanna Arhipova79ae9ec2020-01-27 14:32:17 +0200830 retry: {count: 3, delay: 10}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300831 skip_fail: false
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200832 {%- else %}
833- description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }}
834 cmd: echo "SSH to $(hostname -f) passed"
835 node_name: {{ ssh['node_name'] }}
Hanna Arhipova79ae9ec2020-01-27 14:32:17 +0200836 retry: {count: 3, delay: 10}
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200837 skip_fail: false
838 {%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300839
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200840{%- endfor %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300841
842- description: Accept salt keys from all the nodes
843 cmd: salt-key -A -y
844 node_name: {{ HOSTNAME_CFG01 }}
845 retry: {count: 1, delay: 5}
846 skip_fail: true
Hanna Arhipova54fec802020-10-30 12:45:46 +0200847
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300848{%- endmacro %}
849
850
Hanna Arhipova54fec802020-10-30 12:45:46 +0200851
852{%- macro DISABLE_EMPTY_NODE() %}
853{#######################################}
854{%- for ssh in config.underlay.ssh %}
855 {%- set none_roles = [] %}
856 {%- for role in ssh['roles'] %}
857 {%- if role == "none" %}
858 {%- set _ = none_roles.append(role) %}
859 {%- endif %}
860 {%- endfor %}
861
862 {%- if none_roles %}
863- description: Move non-product node out of Salt Cluster ( {{ ssh['node_name'] }} )
864 cmd: |
865 set -ex;
866 # Use salt-key -a {{ ssh['node_name'] }} --include-all -y command to return node back
867 salt-key -r {{ ssh['node_name'] }} --include-all -y
868 node_name: {{ HOSTNAME_CFG01 }}
869 retry: { count: 1, delay: 5 }
870 skip_fail: true
871 {%- endif %}
872{%- endfor %}
873{%- endmacro %}
874
875
876
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200877{%- macro MACRO_INSTALL_FORMULAS(FORMULA_SERVICES='') %}
878{#######################################################}
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300879- description: Install salt formulas
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200880 cmd: |
881 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300882 set -x;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200883 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
884 which wget > /dev/null || (apt-get update; apt-get install -y wget);
885 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
886 # echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
887 # wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
888 apt-get clean; apt-get update;
889 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
890 declare -a formula_services=({{ FORMULA_SERVICES }});
891 echo -e "\nInstalling all required salt formulas\n";
892 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300893 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200894 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
895 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
896 done;
897 node_name: {{ HOSTNAME_CFG01 }}
898 retry: {count: 1, delay: 1}
899 skip_fail: false
Dennis Dmitriev010f0292018-07-28 23:33:48 +0300900
901- description: Sync all salt resources on salt-master minion
902 cmd: salt-call saltutil.sync_all && sleep 5
903 node_name: {{ HOSTNAME_CFG01 }}
904 retry: {count: 1, delay: 5}
905 skip_fail: false
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200906{%- endmacro %}
907
908{%- macro MACRO_CONFIG_DAY01_SALT_MINION() %}
909{#######################################}
910- description: Configure salt-minion on {{ HOSTNAME_CFG01 }}
911 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300912 set -ex;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200913 export SALT_MASTER_MINION_ID={{ HOSTNAME_CFG01 }}
914 envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
915 service salt-minion restart
916
917 while true; do
918 salt-key | grep "$SALT_MASTER_MINION_ID" && break
919 sleep 5
920 done
921
922 sleep 5
923
924 for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do
925 salt-key -d $i -y
926 done
927 node_name: {{ HOSTNAME_CFG01 }}
928 retry: {count: 1, delay: 1}
929 skip_fail: false
930{%- endmacro %}
931
932
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300933{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
934{##################################################}
935
936{# Prepare salt services and nodes settings #}
937
sgudz6e797562018-10-22 12:27:09 +0300938- description: '*Workaround* of harcoded host from day01 grains'
939 cmd: salt-key -d cfg01.mcp-day01.local -y
940 node_name: {{ HOSTNAME_CFG01 }}
941 retry: {count: 1, delay: 1}
942 skip_fail: true
943
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300944- description: Run 'linux' formula on cfg01
945 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
946 node_name: {{ HOSTNAME_CFG01 }}
947 retry: {count: 3, delay: 5}
948 skip_fail: false
949
950- description: Run 'openssh' formula on cfg01
951 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300952 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300953 salt --hard-crash --state-output=mixed --state-verbose=False
954 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +0300955 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300956 node_name: {{ HOSTNAME_CFG01 }}
957 retry: {count: 3, delay: 5}
958 skip_fail: false
959
960- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
961 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
962 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
963 node_name: {{ HOSTNAME_CFG01 }}
964 retry: {count: 1, delay: 1}
965 skip_fail: false
966
967- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300968 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 +0300969 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300970 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300971 skip_fail: false
972
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400973{%- if SALT_FORMULAS_REFS != '' %}
974- description: Replace needed formulas to desired version
975 cmd: |
976 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300977 set -x;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400978 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
979 {% set formula = formula_set.split(':') %}
980 {% set formula_name = formula[0] %}
981 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300982 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400983 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
984 pushd {{ formula_dir }} &&
985 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
986 git checkout FETCH_HEAD &&
987 popd &&
988 if [ -d "{{ formula_dir }}" ]; then
989 echo "Going to replace packaged formula {{ formula_name }}" &&
990 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400991 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
992 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400993 else
994 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
995 fi
996 {%- endfor %}
997 node_name: {{ HOSTNAME_CFG01 }}
998 retry: {count: 1, delay: 10}
999 skip_fail: false
1000{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001001
1002- description: Refresh pillars on salt-master minion
1003 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
1004 node_name: {{ HOSTNAME_CFG01 }}
1005 retry: {count: 1, delay: 5}
1006 skip_fail: false
1007
Dennis Dmitriev3e731a42017-08-30 17:12:59 +03001008- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001009 cmd: reclass-salt --top
1010 node_name: {{ HOSTNAME_CFG01 }}
1011 retry: {count: 1, delay: 5}
1012 skip_fail: false
1013
1014- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +03001015 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 +03001016 node_name: {{ HOSTNAME_CFG01 }}
1017 retry: {count: 1, delay: 5}
1018 skip_fail: false
1019
1020- description: Configure linux on master
1021 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
1022 node_name: {{ HOSTNAME_CFG01 }}
1023 retry: {count: 1, delay: 5}
1024 skip_fail: false
1025
1026- description: Configure salt.minion on master
1027 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
1028 -C 'I@salt:master' state.sls salt.minion && sleep 10
1029 node_name: {{ HOSTNAME_CFG01 }}
1030 retry: {count: 3, delay: 10}
1031 skip_fail: false
1032
1033- description: Run state 'salt' on master (for salt.api, etc)
1034 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
1035 -C 'I@salt:master' state.sls salt
1036 node_name: {{ HOSTNAME_CFG01 }}
1037 retry: {count: 3, delay: 10}
1038 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001039
1040- description: Restart salt-api after states
1041 cmd: systemctl restart salt-api
1042 node_name: {{ HOSTNAME_CFG01 }}
1043 retry: {count: 3, delay: 10}
1044 skip_fail: false
1045
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001046{%- endmacro %}
1047
Dennis Dmitriev85559962018-01-30 15:35:51 +02001048{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
1049{#################################################################}
1050
1051- description: Refresh pillars before generating nodes
1052 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1053 node_name: {{ HOSTNAME_CFG01 }}
1054 retry: {count: 1, delay: 5}
1055 skip_fail: false
1056
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +02001057- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +02001058 cmd: |
1059 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +03001060 set -x;
Dennis Dmitriev54a13002018-03-01 11:37:04 +02001061 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
1062 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +02001063 node_name: {{ HOSTNAME_CFG01 }}
1064 retry: {count: 1, delay: 5}
1065 skip_fail: false
1066
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001067- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
1068 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
1069 -C 'I@salt:master' state.sls reclass
1070 node_name: {{ HOSTNAME_CFG01 }}
1071 retry: {count: 1, delay: 5}
1072 skip_fail: false
1073
Dennis Dmitriev85559962018-01-30 15:35:51 +02001074{%- if RERUN_SALTMASTER_STATE %}
1075- description: Regenerate salt.master states for the newly uploaded/created model
1076 cmd: |
1077 # Need to refresh installed formulas that are required in the model
1078 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
1079 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
1080 node_name: {{ HOSTNAME_CFG01 }}
1081 retry: {count: 1, delay: 5}
1082 skip_fail: false
1083{%- endif %}
1084
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001085- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +02001086 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001087 node_name: {{ HOSTNAME_CFG01 }}
1088 retry: {count: 1, delay: 5}
1089 skip_fail: false
1090
Dennis Dmitriev3e731a42017-08-30 17:12:59 +03001091- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +03001092 cmd: |
1093 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +03001094 set -x;
Dennis Dmitriev4386a072017-09-04 13:58:02 +03001095 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
1096 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
1097 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001098 node_name: {{ HOSTNAME_CFG01 }}
1099 retry: {count: 1, delay: 5}
1100 skip_fail: false
1101
1102- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +03001103 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001104 node_name: {{ HOSTNAME_CFG01 }}
1105 retry: {count: 1, delay: 5}
1106 skip_fail: false
1107{%- endmacro %}
1108
1109
1110{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
1111{########################################}
1112# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +02001113
1114- description: Get linux kernel version from all minions
1115 cmd: |
1116 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
1117 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
1118 node_name: {{ HOSTNAME_CFG01 }}
1119 retry: {count: 5, delay: 10}
1120 skip_fail: false
1121
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001122- description: Configure linux on other nodes
1123 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
1124 node_name: {{ HOSTNAME_CFG01 }}
1125 retry: {count: 5, delay: 10}
1126 skip_fail: false
1127
1128- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +03001129 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 +03001130 salt --hard-crash --state-output=mixed --state-verbose=False
1131 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +03001132 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001133 node_name: {{ HOSTNAME_CFG01 }}
1134 retry: {count: 1, delay: 5}
1135 skip_fail: false
1136
1137- description: Configure salt.minion on other nodes
1138 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion &&
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001139 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001140 node_name: {{ HOSTNAME_CFG01 }}
1141 retry: {count: 3, delay: 15}
1142 skip_fail: false
1143
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001144- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +04001145 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001146 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +04001147 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001148 skip_fail: false
1149
Victor Ryzhenkina06443e2018-03-15 17:25:19 +04001150- description: Update minion information
Dennis Dmitrievea291ee2018-03-16 12:27:43 +02001151 cmd: |
1152 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001153 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 60
Victor Ryzhenkina06443e2018-03-15 17:25:19 +04001154 node_name: {{ HOSTNAME_CFG01 }}
1155 retry: {count: 1, delay: 10}
1156 skip_fail: false
1157
Dennis Dmitriev14183db2018-03-01 15:14:12 +02001158- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
1159 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
1160 node_name: {{ HOSTNAME_CFG01 }}
1161 retry: {count: 1, delay: 10}
1162 skip_fail: false
1163
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001164- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001165 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001166 node_name: {{ HOSTNAME_CFG01 }}
1167 retry: {count: 3, delay: 15}
1168 skip_fail: false
1169
1170- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001171 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001172 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001173 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001174 skip_fail: false
1175
1176- description: Configure ntp and rsyslog on nodes
1177 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
1178 node_name: {{ HOSTNAME_CFG01 }}
1179 retry: {count: 1, delay: 10}
1180 skip_fail: false
Tatyana Leontovich529e4052018-07-09 18:30:48 +03001181
1182- description: Install and configure iptables if it is in pillar
1183 cmd: |
1184 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' match.pillar 'iptables:service' ; then
1185 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' state.sls iptables
1186 fi
1187 node_name: {{ HOSTNAME_CFG01 }}
1188 retry: {count: 1, delay: 10}
1189 skip_fail: false
1190
1191
1192- description: Install and configure logrotate if it is in pillar
1193 cmd: |
1194 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' match.pillar 'logrotate:server' ; then
1195 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' state.sls logrotate
1196 fi
1197 node_name: {{ HOSTNAME_CFG01 }}
1198 retry: {count: 1, delay: 10}
1199 skip_fail: false
1200
1201- description: Install and configure auditd if it is enabled
1202 cmd: |
1203 if salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" match.pillar 'auditd:service'; then
1204 salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" state.sls auditd
1205 fi
1206 node_name: {{ HOSTNAME_CFG01 }}
1207 retry: {count: 1, delay: 10}
1208 skip_fail: false
1209
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02001210{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001211
1212
1213{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
1214{#########################################}
1215
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001216- description: '*Workaround: Load bonding module before call state.linux'
1217 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
1218 node_name: {{ HOSTNAME_CFG01 }}
1219 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +03001220 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001221
1222- description: '*Workaround* install bridge-utils before running linux formula'
1223 # The formula removes default route and then tries to install the package, fails.
1224 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
1225 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
1226 node_name: {{ HOSTNAME_CFG01 }}
1227 retry: {count: 1, delay: 5}
1228 skip_fail: false
1229
1230{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001231
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001232
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001233{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001234{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001235
1236- description: Set k8s deploy parameters
1237 cmd: |
1238 {% for k8s_opt, value in config.k8s_deploy.items() %}
1239 {% if value|string() %}
1240 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
1241 {% endif %}
1242 {% endfor %}
1243 node_name: {{ HOSTNAME_CFG01 }}
1244 retry: {count: 1, delay: 1}
1245 skip_fail: false
1246
1247{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001248
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001249
1250{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
1251{#############################################}
1252- description: Set SL docker images deploy parameters
1253 cmd: |
1254 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
1255 {%- for sl_opt, value in config.sl_deploy.items() %}
1256 {%- if value|string() %}
1257 {%- if OVERRIDES_FILENAME %}
1258 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
1259 {%- else %}
1260 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
1261 {%- endif %}
1262 {%- endif %}
1263 {%- endfor %}
1264 salt '*' saltutil.refresh_pillar;
1265 sleep 10
1266 node_name: {{ HOSTNAME_CFG01 }}
1267 retry: {count: 1, delay: 1}
1268 skip_fail: false
1269{%- endmacro %}
1270
1271
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001272{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001273{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001274
1275{% for ssh in config.underlay.ssh %}
1276{% if ssh["node_name"].startswith("cmp") %}
1277{% set node_hostname = ssh["node_name"].split('.')[0] %}
1278- description: Register compute {{ ssh['node_name'] }}
1279 cmd: |
1280 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
1281 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
1282 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +04001283 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001284 export config_host={{ config.salt.salt_master_host }}
1285 export node_domain={{ DOMAIN_NAME }}
1286 export nodes_os="xenial"
1287 export node_hostname={{ node_hostname }}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001288 export saltversion={{ SALT_VERSION }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001289 set -xe
1290 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
1291 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
1292 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
1293 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
1294
1295 # Add wrapper to apt-get to avoid race conditions
1296 # with cron jobs running 'unattended-upgrades' script
1297 aptget_wrapper() {
1298 local apt_wrapper_timeout=300
1299 local start_time=$(date '+%s')
1300 local fin_time=$((start_time + apt_wrapper_timeout))
1301 while true; do
1302 if (( "$(date '+%s')" > fin_time )); then
1303 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
1304 fi
1305 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
1306 echo "Waiting while another apt/dpkg process releases locks ..."
1307 sleep 30
1308 continue
1309 else
1310 apt-get $@
1311 break
1312 fi
1313 done
1314 }
1315
1316 # Set default salt version
1317 if [ -z "$saltversion" ]; then
Tatyana Leontovich14e201d2018-07-05 13:28:54 +03001318 saltversion="2017.7"
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001319 fi
1320 echo "Using Salt version $saltversion"
1321
1322 echo "Preparing base OS ..."
1323
1324 case "$node_os" in
1325 trusty)
1326 # workaround for old cloud-init only configuring the first iface
1327 iface_config_dir="/etc/network/interfaces"
1328 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
1329
1330 for iface in $ifaces; do
1331 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
1332 done
1333
1334 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1335
1336 # SUGGESTED UPDATE:
1337 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1338 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1339 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1340 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1341 #install_salt_minion_pkg
1342
1343 # DEPRECATED:
1344 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1345 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1346
1347 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
1348 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1349
1350 aptget_wrapper clean
1351 aptget_wrapper update
1352 aptget_wrapper install -y salt-common
1353 aptget_wrapper install -y salt-minion
1354 ;;
1355 xenial)
1356
1357 # workaround for new cloud-init setting all interfaces statically
1358 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
1359
1360 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1361
1362 # SUGGESTED UPDATE:
1363 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1364 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1365 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1366 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1367 #install_salt_minion_pkg
1368
1369 # DEPRECATED:
1370 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1371 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1372
1373 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
1374 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1375
1376 aptget_wrapper clean
1377 aptget_wrapper update
1378 aptget_wrapper install -y salt-minion
1379 ;;
1380 rhel|centos|centos7|centos7|rhel6|rhel7)
1381 yum install -y git
1382 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1383 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1384 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1385 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1386 install_salt_minion_pkg
1387 ;;
1388 *)
1389 msg="OS '$node_os' is not supported."
1390 esac
1391
1392 echo "Configuring Salt minion ..."
1393 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
1394 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
1395
1396 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
1397
1398 sleep 1
1399
1400 echo "Classifying node ..."
1401 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
1402 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1403 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1404 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1405 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1406 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1407
1408 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1409 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1410 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1411 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1412 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1413
1414 if [ "$node_network05_iface" != "" ]; then
1415 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
1416 fi
1417
1418 # find more parameters (every env starting param_)
1419 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
1420 if [ "$more_params" != "" ]; then
1421 echo "Additional params: $more_params"
1422 more_params=", $more_params"
1423 fi
1424
1425 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}}"
1426
1427 sleep 5
1428
1429 salt-call saltutil.sync_all
1430 salt-call mine.flush
1431 salt-call mine.update
1432 node_name: {{ ssh['node_name'] }}
1433 retry: {count: 1, delay: 1}
1434 skip_fail: false
1435{%- endif %}
1436{%- endfor %}
1437
1438- description: Refresh pillars on all minions
1439 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1440 node_name: {{ HOSTNAME_CFG01 }}
1441 retry: {count: 1, delay: 5}
1442 skip_fail: false
1443
1444- description: Sync all salt resources
1445 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1446 node_name: {{ HOSTNAME_CFG01 }}
1447 retry: {count: 1, delay: 5}
1448 skip_fail: false
1449
sgudz160b7302017-12-22 17:01:10 +02001450{%- endmacro %}
sgudz09e9aa92018-04-12 12:31:53 +03001451
1452{%- macro RUN_NEW_TEMPEST() %}
1453{###################################}
1454
1455- description: Upload tempest template
1456 upload:
1457 local_path: {{ config.salt_deploy.templates_dir }}
1458 local_filename: runtest.yml
1459 remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/
1460 node_name: {{ HOSTNAME_CFG01 }}
1461 skip_fail: False
1462
1463- description: Include class with tempest template into cfg node
1464 cmd: |
1465 sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml;
1466 salt 'cfg01*' saltutil.refresh_pillar;
1467 salt 'cfg01*' saltutil.sync_all;
1468 node_name: {{ HOSTNAME_CFG01 }}
1469 retry: {count: 1, delay: 10}
1470 skip_fail: false
1471
Oleksii Butenko2e8e8ee2018-06-21 11:10:13 +03001472- description: Execute salt.minion on config node
1473 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False state.sls salt.minion;
1474 node_name: {{ HOSTNAME_CFG01 }}
1475 retry: {count: 1, delay: 5}
1476 skip_fail: false
1477
1478- description: Test ping
1479 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False test.ping;
1480 node_name: {{ HOSTNAME_CFG01 }}
1481 retry: {count: 1, delay: 5}
1482 skip_fail: false
1483
sgudz09e9aa92018-04-12 12:31:53 +03001484- description: Create flavors for tests
1485 cmd: |
1486 salt 'cfg01*' state.sls nova.client;
1487 node_name: {{ HOSTNAME_CFG01 }}
1488 retry: {count: 1, delay: 5}
1489 skip_fail: false
1490
1491- description: Create networks for tests
1492 cmd: |
1493 salt 'cfg01*' state.sls neutron.client;
1494 node_name: {{ HOSTNAME_CFG01 }}
1495 retry: {count: 1, delay: 5}
1496 skip_fail: false
1497
1498- description: Upload cirros image
1499 cmd: |
1500 salt 'cfg01*' state.sls glance.client;
1501 node_name: {{ HOSTNAME_CFG01 }}
1502 retry: {count: 1, delay: 5}
1503 skip_fail: false
1504
1505- description: Generate tempest config
1506 cmd: |
1507 salt 'cfg01*' state.sls runtest;
1508 node_name: {{ HOSTNAME_CFG01 }}
1509 retry: {count: 1, delay: 5}
1510 skip_fail: false
1511
1512- description: Run tempest from new docker image
1513 cmd: |
Oleksii Butenko71d76f32018-06-05 17:46:34 +03001514 docker run -e ARGS="-r {{TEMPEST_PATTERN }} -w 2 {{ EXCLUDE_TEST_ARGS }}" -v /root/test/tempest.conf:/etc/tempest/tempest.conf -v /tmp/:/tmp/ -v /root/test:/root/tempest -v /etc/ssl/certs/:/etc/ssl/certs/ --rm docker-prod-virtual.docker.mirantis.net/mirantis/cicd/ci-tempest:pike /bin/bash -c "run-tempest"
sgudz09e9aa92018-04-12 12:31:53 +03001515 node_name: {{ HOSTNAME_GTW01 }}
1516 retry: {count: 1, delay: 30}
1517 skip_fail: true
1518
1519- description: Download xml results
1520 download:
1521 remote_path: /root/test/
1522 remote_filename: "report_*.xml"
1523 local_path: {{ os_env('PWD') }}
1524 node_name: {{ HOSTNAME_GTW01 }}
1525 skip_fail: true
1526
1527{%- endmacro %}
Oleksii Butenko5cd0a162018-06-14 18:18:10 +03001528
1529{%- macro INSTALL_DOCKER_ON_GTW() %}
1530{###################################}
1531
1532- description: Install docker.io on gtw
1533 cmd: salt-call cmd.run 'apt-get install docker.io -y'
1534 node_name: {{ HOSTNAME_GTW01 }}
1535 retry: {count: 1, delay: 30}
1536 skip_fail: false
1537
1538- description: Enable forward policy
1539 cmd: iptables --policy FORWARD ACCEPT
1540 node_name: {{ HOSTNAME_GTW01 }}
1541 retry: {count: 1, delay: 30}
1542 skip_fail: false
1543
1544{%- endmacro %}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001545
1546{%- macro MACRO_CHECK_SALT_VERSION_ON_NODES() %}
1547{#####################################################}
1548
1549{%- for ssh in config.underlay.ssh %}
1550 {%- set salt_roles = [] %}
1551 {%- for role in ssh['roles'] %}
1552 {%- if role in config.salt_deploy.salt_roles %}
1553 {%- set _ = salt_roles.append(role) %}
1554 {%- endif %}
1555 {%- endfor %}
1556
1557 {%- if salt_roles %}
1558- description: 'Check salt version is as expected'
1559 cmd: salt-call test.version | grep {{ SALT_VERSION }}
1560 node_name: {{ ssh['node_name'] }}
1561 retry: {count: 1, delay: 1}
1562 skip_fail: false
1563 {%- endif %}
1564
1565{%- endfor %}
1566{%- endmacro %}
1567
1568{%- macro MACRO_CHECK_SALT_VERSION_SERVICES_ON_CFG() %}
1569{#####################################################}
1570
1571- description: 'Check salt-api, salt-master and salt-minion version'
1572 cmd: |
1573 salt-master --version | grep {{ SALT_VERSION }};
1574 salt-minion --version | grep {{ SALT_VERSION }};
1575 salt-api --version | grep {{ SALT_VERSION }};
1576 node_name: {{ HOSTNAME_CFG01 }}
1577 retry: {count: 1, delay: 5}
1578 skip_fail: false
1579
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001580{%- endmacro %}
Andrew Baraniuk2c06e512019-05-30 17:22:48 +03001581
1582{%- macro MACRO_IPFLUSH_TENANTS_IFACES() %}
1583{######################################}
1584- description: WR Flush addresses on tenant and external ifaces
1585 cmd: |
1586 salt -C 'gtw* or cmp*' cmd.run 'ip address flush dev ens5';
1587 salt -C 'gtw* or cmp*' cmd.run 'ip address flush dev ens6';
1588 node_name: {{ HOSTNAME_CFG01 }}
1589 retry: {count: 1, delay: 1}
1590 skip_fail: false
1591
1592{%- endmacro %}