blob: 1535db651bc5d92ab7236c4aec0c98ec5edd78f4 [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 #}
Dennis Dmitriev3d0ed0a2018-11-23 11:02:52 +00008{% set SALT_MODELS_SYSTEM_REPOSITORY = os_env('SALT_MODELS_SYSTEM_REPOSITORY','https://gerrit.mcp.mirantis.com/salt-models/reclass-system') %}
9{% set SALT_MODELS_SYSTEM_COMMIT = os_env('SALT_MODELS_SYSTEM_COMMIT','') %}
10{% set SALT_MODELS_SYSTEM_REF_CHANGE = os_env('SALT_MODELS_SYSTEM_REF_CHANGE','') %}
11{% set SALT_MODELS_SYSTEM_TAG = os_env('SALT_MODELS_SYSTEM_TAG','') %}
Dennis Dmitriev06979442018-10-24 18:53:49 +030012{% set COOKIECUTTER_TEMPLATES_REPOSITORY_USER = os_env('COOKIECUTTER_TEMPLATES_REPOSITORY_USER','mcp-gerrit') %}
13{% set COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH = os_env('COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH','') %}
14{% 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 +020015{% set COOKIECUTTER_REF_CHANGE = os_env('COOKIECUTTER_REF_CHANGE','') %}
Tatyana Leontovich819a6c82018-06-04 12:05:16 +030016{% set COOKIECUTTER_TAG = os_env('COOKIECUTTER_TAG','') %}
sgudza399dc72018-01-18 17:13:48 +020017{% set COOKIECUTTER_TEMPLATE_COMMIT = os_env('COOKIECUTTER_TEMPLATE_COMMIT','') %}
Vladimir Khlyunevf337c902018-12-06 12:29:24 +040018{% set ENVIRONMENT_TEMPLATE_COMMIT = os_env('ENVIRONMENT_TEMPLATE_COMMIT','') %}
sgudzcced67d2017-10-11 15:56:09 +030019{% set ENVIRONMENT_TEMPLATE_REF_CHANGE = os_env('ENVIRONMENT_TEMPLATE_REF_CHANGE','') %}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +030020# Currently we support 2 salt version that can be set over bellow var
Tatyana Leontovich14e201d2018-07-05 13:28:54 +030021{% set SALT_VERSION = os_env('SALT_VERSION','2017.7') %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +030022{% set REPOSITORY_SUITE = os_env('REPOSITORY_SUITE', 'testing') %}
Tatyana Leontovich6603e902018-12-04 15:11:19 +020023#{% set FORMULA_REPOSITORY = os_env('FORMULA_REPOSITORY', 'deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME} ' + REPOSITORY_SUITE + ' salt extra') %}
24{% set FORMULA_REPOSITORY = os_env('FORMULA_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE+ "/salt-formulas"+"/${DISTRIB_CODENAME} ${DISTRIB_CODENAME} main") %}
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020025{% set FORMULA_GPG = os_env('FORMULA_GPG', 'http://apt.mirantis.com/public.gpg') %}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +030026#{# set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME}/salt/2016.3 " + REPOSITORY_SUITE + " main") #}
27# Note repo is changed so new one looks like defined bellow
28{% 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 Dmitrievcf777802018-02-14 18:09:55 +020029{% set SALT_GPG = os_env('SALT_GPG', 'http://apt.mirantis.com/public.gpg') %}
30{% set UBUNTU_REPOSITORY = os_env('UBUNTU_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME} main restricted universe") %}
31{% 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") %}
32{% 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 +030033{% set UBUNTU_KEY_SERVER = os_env('UBUNTU_KEY_SERVER', 'keyserver.ubuntu.com') %}
Tatyana Leontovich908ab932018-04-27 01:25:09 +030034{% set UBUNTU_KEY_ID = os_env('UBUNTU_KEY_ID', '0E08A149DE57BFBE') %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +030035
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020036{# Address pools for reclass cluster model are taken in the following order:
37 # 1. environment variables,
38 # 2. config.underlay.address_pools based on fuel-devops address pools
39 # (see generated '.ini' file after underlay is created),
40 # 3. defaults #}
41{% set address_pools = config.underlay.address_pools %}
42{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
43{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
44{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
45{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
46{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
47{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
48{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
49{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
50
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040051{# Format for formula replacement:
52 # space separated string:
53 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
54
55{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
Tatyana Leontovich1c101312018-04-18 20:33:08 +030056{% set TEMPEST_PATTERN = os_env('TEMPEST_PATTERN', 'tempest') %}
Tatyana Leontovich69700712018-04-23 12:26:57 +030057{% set EXCLUDE_TEST_ARGS = os_env('EXCLUDE_TEST_ARGS', '') %}
Dennis Dmitriev0f272312018-10-01 13:29:40 +030058{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.com/salt-formulas') %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040059
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040060# Needed for using different models in different templates
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020061{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040062
Dennis Dmitriev492813e2017-08-09 15:08:58 +030063
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020064{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
65{#####################################################}
66
67- description: 'Configure key on nodes and install packages'
68 cmd: |
69 rm -rf trusted* ;
70 rm -rf /etc/apt/sources.list ;
Dennis Dmitrievcf777802018-02-14 18:09:55 +020071 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020072 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
73 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
74 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +030075 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020076 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
77 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
78 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
Dennis Dmitrievf4e6efc2018-03-26 06:15:10 -050079 eatmydata apt-get clean;
80 apt-get update;
Dennis Dmitriev01d5e372018-03-15 23:29:29 +020081 sync;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020082 node_name: {{ NODE_NAME }}
83 retry: {count: 1, delay: 5}
84 skip_fail: false
85
86{%- endmacro %}
87
88
Dennis Dmitriev492813e2017-08-09 15:08:58 +030089{%- macro MACRO_INSTALL_SALT_MASTER() %}
90{######################################}
91- description: Installing salt master on cfg01
Dennis Dmitrievcf777802018-02-14 18:09:55 +020092 cmd: |
93 which wget >/dev/null || (apt-get update; apt-get install -y wget);
94 # Configure ubuntu and salt repositories
95 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
96 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
97 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
98 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
99
100 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
101 wget -O - {{ FORMULA_GPG }} | apt-key add -;
102 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300103 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
104
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200105
106 apt-get clean
107 apt-get update
108
109 # Install salt-master and reclass
110 eatmydata apt-get install -y --allow-unauthenticated reclass salt-master
111 # Install common packages
Dennis Dmitrievf88fc7d2018-02-20 15:40:08 +0200112 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 +0200113 sync;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300114 node_name: {{ HOSTNAME_CFG01 }}
115 retry: {count: 1, delay: 1}
116 skip_fail: false
117
Dennis Dmitrievda9be462018-01-24 21:20:09 +0200118- description: Remove any existing minion keys
119 cmd: salt-key -y -D || true
120 node_name: {{ HOSTNAME_CFG01 }}
121 retry: {count: 1, delay: 1}
122 skip_fail: false
123
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300124- description: Configure salt-master on cfg01
125 cmd: |
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200126 cat << 'EOF' > /etc/salt/master.d/master.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300127 file_roots:
128 base:
129 - /usr/share/salt-formulas/env
130 pillar_opts: False
131 open_mode: True
132 reclass: &reclass
133 storage_type: yaml_fs
134 inventory_base_uri: /srv/salt/reclass
135 ext_pillar:
136 - reclass: *reclass
137 master_tops:
138 reclass: *reclass
139 EOF
140 node_name: {{ HOSTNAME_CFG01 }}
141 retry: {count: 1, delay: 1}
142 skip_fail: false
143
144- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300145 cmd: |
146 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200147 #touch /root/.git_trusted_certs.pem;
148 #for server in github.com; do \
149 # openssl s_client -showcerts -connect $server:443 </dev/null \
150 # | openssl x509 -outform PEM \
151 # >> /root/.git_trusted_certs.pem;
152 #done;
153 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
154 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
155 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300156 node_name: {{ HOSTNAME_CFG01 }}
157 retry: {count: 1, delay: 1}
158 skip_fail: false
159{%- endmacro %}
160
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200161
162{%- macro MACRO_CONFIG_DAY01_SALT_MASTER() %}
163{######################################}
164
165- description: Remove /etc/update-motd.d/52-info
166 cmd: rm -vf /etc/update-motd.d/52-info
167 node_name: {{ HOSTNAME_CFG01 }}
168 retry: {count: 1, delay: 10}
169 skip_fail: false
170
171- description: Set up static interface config
172 cmd: |
173 kill $(pidof /sbin/dhclient) || /bin/true
174 cat << 'EOF' > /etc/network/interfaces
175 # This file describes the network interfaces available on your system
176 # and how to activate them. For more information, see interfaces(5).
177
178 # The loopback network interface
179 auto lo
180 iface lo inet loopback
181
182 # The primary network interface
183 auto ens3
184 iface ens3 inet static
185 address {{ IPV4_NET_ADMIN_PREFIX }}.90
186 netmask 255.255.255.0
187 gateway {{ IPV4_NET_ADMIN_PREFIX }}.1
188 EOF
189 node_name: {{ HOSTNAME_CFG01 }}
190 retry: {count: 1, delay: 10}
191 skip_fail: false
192
193- description: Install common packages on cfg01
194 cmd: eatmydata apt-get update && apt-get install -y python-pip git curl at tmux byobu iputils-ping traceroute htop tree wget jq ntpdate
195 node_name: {{ HOSTNAME_CFG01 }}
196 retry: {count: 1, delay: 1}
197 skip_fail: false
198
199- description: Remove any existing minion keys
200 cmd: salt-key -y -D || true
201 node_name: {{ HOSTNAME_CFG01 }}
202 retry: {count: 1, delay: 1}
203 skip_fail: false
204
205- description: Configure GIT settings and certificates
206 cmd: |
207 set -e;
208 #touch /root/.git_trusted_certs.pem;
209 #for server in github.com; do \
210 # openssl s_client -showcerts -connect $server:443 </dev/null \
211 # | openssl x509 -outform PEM \
212 # >> /root/.git_trusted_certs.pem;
213 #done;
214 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
215 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
216 HOME=/root git config --global user.name "MCP Integration QA";
217 node_name: {{ HOSTNAME_CFG01 }}
218 retry: {count: 1, delay: 1}
219 skip_fail: false
220{%- endmacro %}
221
222
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300223{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false, WITH_MAAS=false) %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300224{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300225{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
226
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300227- description: Clone reclass models with submodules
228 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300229 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200230 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200231 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200232
233 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
234 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 +0200235 rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200236
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200237 pushd /srv/salt/reclass;
238 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
239 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200240 {%- if SALT_MODELS_REF_CHANGE != '' %}
241 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200242 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200243 {%- endfor %}
244 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200245 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200246 {%- endif %}
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300247
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300248 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300249 pushd classes/system/ && \
250 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200251 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300252 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200253 popd;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300254 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
255 pushd classes/system/;
256 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
257 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300258 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
259 pushd classes/system/;
260 git fetch --all --tags --prune
261 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
262 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200263 {%- endif %}
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300264
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200265 popd;
266 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300267 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200268
269 # Replace firstly to an intermediate value to avoid intersection between
270 # already replaced and replacing networks.
271 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
272 # 192.168.10 -> 10.16.0 (generated network for admin)
273 # 10.16.0 -> <external network>
274 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300275 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200276 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10/==IPV4_NET_ADMIN_PREFIX==/g' {} +
277 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10/==IPV4_NET_CONTROL_PREFIX==/g' {} +
278 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0/==IPV4_NET_TENANT_PREFIX==/g' {} +
279 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Tatyana Leontovich26756912018-06-06 20:11:05 +0300280 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.60\.0/==IPV4_NET_CONTROL_PREFIX==/g' {} +
281 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.70\.0/==IPV4_NET_ADMIN_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200282
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200283 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
284 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
285 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
286 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 +0200287
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300288 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 +0200289
Tatyana Leontovicha4a96b22018-04-25 14:30:24 +0300290 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300291 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300292 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 +0300293 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 +0300294 {%- endif %}
295
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200296 # Override some context parameters
297 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
298 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
299 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
300
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200301 # Create the cfg01 inventory file or use existing
302 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
303 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300304 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400305 - cluster.{{ CLUSTER_NAME }}.infra.config
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300306 {%- if WITH_MAAS %}
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200307 - cluster.{{ CLUSTER_NAME }}.infra.maas
308 - cluster.{{ CLUSTER_NAME }}.infra.maas-machines
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300309 {%- endif %}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300310 parameters:
311 _param:
312 linux_system_codename: xenial
313 reclass_data_revision: master
314 linux:
315 system:
316 name: cfg01
317 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200318 reclass:
319 storage:
320 data_source:
321 engine: local
322 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300323
324 # Show the changes to the console
325 cd /srv/salt/reclass/; git diff
326 node_name: {{ HOSTNAME_CFG01 }}
327 retry: {count: 1, delay: 1}
328 skip_fail: false
329{%- endmacro %}
330
331
sgudz160b7302017-12-22 17:01:10 +0200332{%- 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 +0300333{###################################################################}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300334{%- set CLUSTER_CONTEXT_PATH = '/root/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200335- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300336 upload:
337 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
338 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300339 remote_path: /root/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300340 node_name: {{ HOSTNAME_CFG01 }}
341
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300342- description: "Show options enabled in the context file for model generation"
343 cmd: |
344 echo "===== Options enabled in the context for generation the model {{ LAB_CONFIG_NAME }} ====="
345 fgrep "True" {{ CLUSTER_CONTEXT_PATH }}
346 echo "===== Sources for model generation ====="
347 echo "# mcp_version: {{ REPOSITORY_SUITE }}"
348 echo "COOKIECUTTER_TEMPLATES_REPOSITORY={{ COOKIECUTTER_TEMPLATES_REPOSITORY }}"
349 {%- if CLUSTER_PRODUCT_MODELS != '' %}
350 echo "CLUSTER_PRODUCT_MODELS={{ CLUSTER_PRODUCT_MODELS }}"
351 {%- endif %}
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300352 {%- if COOKIECUTTER_REF_CHANGE != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300353 echo "COOKIECUTTER_REF_CHANGE={{ COOKIECUTTER_REF_CHANGE }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300354 {%- elif COOKIECUTTER_TEMPLATE_COMMIT != '' %}
355 echo "COOKIECUTTER_TEMPLATE_COMMIT={{ COOKIECUTTER_TEMPLATE_COMMIT }}"
Dennis Dmitriev713dce22018-07-03 11:47:46 +0300356 {%- elif COOKIECUTTER_TAG != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300357 echo "COOKIECUTTER_TAG={{ COOKIECUTTER_TAG }}"
358 {%- endif %}
359 echo "SALT_MODELS_SYSTEM_REPOSITORY={{ SALT_MODELS_SYSTEM_REPOSITORY }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300360 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300361 echo "SALT_MODELS_SYSTEM_REF_CHANGE={{ SALT_MODELS_SYSTEM_REF_CHANGE }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300362 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
363 echo "SALT_MODELS_SYSTEM_COMMIT={{ SALT_MODELS_SYSTEM_COMMIT }}"
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300364 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
365 echo "SALT_MODELS_SYSTEM_TAG={{ SALT_MODELS_SYSTEM_TAG }}"
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300366 {%- endif %}
367 echo "======================================="
368 node_name: {{ HOSTNAME_CFG01 }}
369 retry: {count: 1, delay: 1}
370 skip_fail: false
371
Dennis Dmitriev06979442018-10-24 18:53:49 +0300372- description: "Upload {{ COOKIECUTTER_TEMPLATES_REPOSITORY_USER }} key"
373 upload:
374 local_path: {{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | dirname }}/
375 local_filename: {{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
376 remote_path: /tmp/
377 node_name: {{ HOSTNAME_CFG01 }}
378
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300379- description: Create cluster model from cookiecutter templates
380 cmd: |
381 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300382 set -x;
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300383 sudo apt-get install python-setuptools -y
Dennis Dmitrievb4b74032018-12-18 21:53:23 +0200384
385 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
386 . /root/venv-reclass-tools/bin/activate;
387 pip install -U pip
388
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300389 pip install cookiecutter
Dennis Dmitriev06979442018-10-24 18:53:49 +0300390
391 chmod 0600 /tmp/{{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
392 eval $(ssh-agent)
393 ssh-add /tmp/{{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300394 export GIT_SSL_NO_VERIFY=true; git clone {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} /root/cookiecutter-templates
sgudz4d816eb2017-11-13 11:58:05 +0200395
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300396 {%- if COOKIECUTTER_REF_CHANGE != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300397 pushd /root/cookiecutter-templates
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300398 git fetch {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
sgudz4d816eb2017-11-13 11:58:05 +0200399 popd
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300400 {%- elif COOKIECUTTER_TEMPLATE_COMMIT != '' %}
401 pushd /root/cookiecutter-templates
402 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
403 popd
Dennis Dmitriev713dce22018-07-03 11:47:46 +0300404 {%- elif COOKIECUTTER_TAG != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300405 pushd /root/cookiecutter-templates
Tatyana Leontovich819a6c82018-06-04 12:05:16 +0300406 git fetch --all --tags --prune
407 git checkout tags/{{ COOKIECUTTER_TAG }}
408 popd
409 {%- endif %}
410
Dennis Dmitrievddcea2f2018-12-18 21:21:11 +0200411 if [ -f /root/cookiecutter-templates/requirements.txt ]; then
412 pip install -r /root/cookiecutter-templates/requirements.txt
413 fi
414
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300415 mkdir -p /srv/salt/reclass/classes/cluster/
416 mkdir -p /srv/salt/reclass/classes/system/
417 mkdir -p /srv/salt/reclass/classes/service/
418 mkdir -p /srv/salt/reclass/nodes/_generated
419
420 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200421 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
422 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200423 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300424 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200425 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300426 {%- endif %}
427 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200428 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300429 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300430
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300431 # Replace firstly to an intermediate value to avoid intersection between
432 # already replaced and replacing networks.
433 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
434 # 192.168.10 -> 10.16.0 (generated network for admin)
435 # 10.16.0 -> <external network>
436 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300437 export REPLACE_DIRS="{{ CLUSTER_CONTEXT_PATH }} /root/cookiecutter-templates"
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300438 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
439 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
440 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
441 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300442
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300443 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
444 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
445 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
446 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 +0300447
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300448 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /root/cookiecutter-templates/cluster_product/)' %}
sgudz160b7302017-12-22 17:01:10 +0200449 for item in {{ items }}; do
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300450 python /root/cookiecutter-templates/generate.py \
451 --template /root/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300452 --config-file {{ CLUSTER_CONTEXT_PATH }} \
453 --output-dir /srv/salt/reclass/classes/cluster/;
454 done
455
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300456 export GIT_SSL_NO_VERIFY=true; git clone {{ SALT_MODELS_SYSTEM_REPOSITORY }} /srv/salt/reclass/classes/system/
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300457
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200458 # Create the cfg01 inventory file or use existing
459 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
460 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300461 classes:
462 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200463 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300464 EOF
465
466 node_name: {{ HOSTNAME_CFG01 }}
467 retry: {count: 1, delay: 1}
468 skip_fail: false
469
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300470- description: Modify generated model and reclass-system if necessary
471 cmd: |
472 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300473 set -x;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300474 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300475 pushd /srv/salt/reclass/classes/system/ && \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300476 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300477 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300478 {%- endfor %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300479 popd;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300480 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
481 pushd /srv/salt/reclass/classes/system/
482 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
483 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300484 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
485 pushd /srv/salt/reclass/classes/system/
486 git fetch --all --tags --prune
487 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
488 popd;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300489 {%- endif %}
490
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300491 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200492 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300493 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
494 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
495 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
496 {%- endif %}
497
498 node_name: {{ HOSTNAME_CFG01 }}
499 retry: {count: 1, delay: 1}
500 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +0300501
502- description: Restart salt-api
503 cmd: |
504 set -e;
505 systemctl restart salt-api
506
507 node_name: {{ HOSTNAME_CFG01 }}
508 retry: {count: 1, delay: 1}
509 skip_fail: false
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300510{%- endmacro %}
511
512
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300513{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
514{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300515
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200516- description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300517 cmd: |
518 set -e;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300519 mkdir -p /root/environment/;
520 export GIT_SSL_NO_VERIFY=true; git clone https://github.com/Mirantis/environment-template /root/environment/environment_template
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300521
Vladimir Khlyunevf337c902018-12-06 12:29:24 +0400522 {%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300523 pushd /root/environment/environment_template &&
sgudzcced67d2017-10-11 15:56:09 +0300524 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
525 git checkout FETCH_HEAD &&
526 popd
Vladimir Khlyunevf337c902018-12-06 12:29:24 +0400527 {%- elif ENVIRONMENT_TEMPLATE_COMMIT != '' %}
528 pushd /root/environment/environment_template
529 git checkout {{ ENVIRONMENT_TEMPLATE_COMMIT }}
530 popd
531 {%- endif %}
532
sgudzcced67d2017-10-11 15:56:09 +0300533 node_name: {{ HOSTNAME_CFG01 }}
534 skip_fail: false
sgudzcced67d2017-10-11 15:56:09 +0300535
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300536{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200537- description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300538 upload:
539 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
540 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300541 remote_path: /root/environment/
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300542 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300543{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300544
Dennis Dmitriev1ddf6472018-11-25 22:30:12 +0200545- description: "Replace template addresses to actual environment addresses"
546 cmd: |
547 set -ex;
548 # Replace firstly to an intermediate value to avoid intersection between
549 # already replaced and replacing networks.
550 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
551 # 192.168.10 -> 10.16.0 (generated network for admin)
552 # 10.16.0 -> <external network>
553 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
554 export REPLACE_DIRS="/root/environment/"
555 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
556 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
557 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
558 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
559
560 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
561 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
562 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
563 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {} +
564 node_name: {{ HOSTNAME_CFG01 }}
565 retry: {count: 1, delay: 5}
566 skip_fail: false
567
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300568- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
569 cmd: |
570 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300571 set -x;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300572 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200573 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
574 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300575 pip install git+https://github.com/dis-xcom/reclass-tools;
576 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
577 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
578 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
579
Dennis Dmitriev6368f082018-02-23 13:30:30 -0500580 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
581 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
582 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 +0300583 fi;
584
585 node_name: {{ HOSTNAME_CFG01 }}
586 retry: {count: 1, delay: 5}
587 skip_fail: false
588
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200589- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300590 cmd: |
591 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200592 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 +0300593
594 node_name: {{ HOSTNAME_CFG01 }}
595 retry: {count: 1, delay: 5}
596 skip_fail: false
597
598- description: "[EXPERIMENTAL] Create environment model for virtual environment"
599 cmd: |
600 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300601 set -x;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200602 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300603 reclass-tools render --template-dir /root/environment/environment_template/ \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300604 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300605 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /root/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300606 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
607 node_name: {{ HOSTNAME_CFG01 }}
608 retry: {count: 1, delay: 5}
609 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300610
611- description: Modify generated model and reclass-system
612 cmd: |
613 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
614 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
615 node_name: {{ HOSTNAME_CFG01 }}
616 retry: {count: 1, delay: 1}
617 skip_fail: false
618
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300619{%- endmacro %}
620
621
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300622{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
623{#######################################################}
624- description: Configure reclass
625 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300626 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300627 set -x;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300628 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300629 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200630 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200631 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
632 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300633 apt-get clean; apt-get update;
634 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
635 declare -a formula_services=({{ FORMULA_SERVICES }});
636 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200637 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300638 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300639 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
640 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
641 done;
642 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
643 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
644 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
645
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200646 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300647 storage_type: yaml_fs
648 pretty_print: True
649 output: yaml
650 inventory_base_uri: /srv/salt/reclass
651 EOF
652 node_name: {{ HOSTNAME_CFG01 }}
653 retry: {count: 1, delay: 1}
654 skip_fail: false
655
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200656- 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 +0300657 cmd: |
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200658 # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top'
659 find /srv/salt/reclass/nodes/ -type f -not -name cfg01.{{ DOMAIN_NAME }}.yml -delete
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300660 node_name: {{ HOSTNAME_CFG01 }}
661 retry: {count: 1, delay: 5}
662 skip_fail: false
663
664- description: Configure salt adoptors on cfg01
665 cmd: |
666 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
667 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
668 node_name: {{ HOSTNAME_CFG01 }}
669 retry: {count: 1, delay: 1}
670 skip_fail: false
671
672- description: Show reclass-salt --top for cfg01 node
673 cmd: reclass-salt --top
674 node_name: {{ HOSTNAME_CFG01 }}
675 retry: {count: 1, delay: 5}
676 skip_fail: false
677
678- description: Restart salt-master service
ibumarskov712a6872018-04-25 09:22:15 +0400679 cmd: service salt-master restart;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300680 node_name: {{ HOSTNAME_CFG01 }}
681 retry: {count: 1, delay: 5}
682 skip_fail: false
683{%- endmacro %}
684
685
686{%- macro MACRO_INSTALL_SALT_MINIONS() %}
687{#######################################}
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200688{%- for ssh in config.underlay.ssh %}
689 {%- set salt_roles = [] %}
690 {%- for role in ssh['roles'] %}
691 {%- if role in config.salt_deploy.salt_roles %}
692 {%- set _ = salt_roles.append(role) %}
693 {%- endif %}
694 {%- endfor %}
695
696 {%- if salt_roles %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300697- description: Configure salt-minion on {{ ssh['node_name'] }}
698 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300699 set -ex;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300700 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitriev3fe24dd2018-07-20 18:38:57 +0300701 cat << EOF > /etc/salt/minion.d/minion.conf
702 id: $(hostname -s).{{ DOMAIN_NAME }}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300703 master: {{ config.salt.salt_master_host }}
704 EOF
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200705
706 # Configure ubuntu and salt repositories
707 which wget >/dev/null || (apt-get update; apt-get install -y wget);
708
709 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
710 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
711 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
712 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
713
714 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300715 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
716
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200717
718 apt-get clean
719 apt-get update
720
721 # Install salt-minion
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300722 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200723 # Install common packages
724 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200725 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200726 # Restart salt-minion if it was already installed
727 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300728 node_name: {{ ssh['node_name'] }}
729 retry: {count: 1, delay: 1}
730 skip_fail: false
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200731 {%- else %}
732- description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }}
733 cmd: echo "SSH to $(hostname -f) passed"
734 node_name: {{ ssh['node_name'] }}
735 retry: {count: 1, delay: 1}
736 skip_fail: false
737 {%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300738
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200739{%- endfor %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300740
741- description: Accept salt keys from all the nodes
742 cmd: salt-key -A -y
743 node_name: {{ HOSTNAME_CFG01 }}
744 retry: {count: 1, delay: 5}
745 skip_fail: true
746{%- endmacro %}
747
748
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200749{%- macro MACRO_INSTALL_FORMULAS(FORMULA_SERVICES='') %}
750{#######################################################}
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300751- description: Install salt formulas
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200752 cmd: |
753 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300754 set -x;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200755 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
756 which wget > /dev/null || (apt-get update; apt-get install -y wget);
757 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
758 # echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
759 # wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
760 apt-get clean; apt-get update;
761 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
762 declare -a formula_services=({{ FORMULA_SERVICES }});
763 echo -e "\nInstalling all required salt formulas\n";
764 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300765 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200766 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
767 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
768 done;
769 node_name: {{ HOSTNAME_CFG01 }}
770 retry: {count: 1, delay: 1}
771 skip_fail: false
Dennis Dmitriev010f0292018-07-28 23:33:48 +0300772
773- description: Sync all salt resources on salt-master minion
774 cmd: salt-call saltutil.sync_all && sleep 5
775 node_name: {{ HOSTNAME_CFG01 }}
776 retry: {count: 1, delay: 5}
777 skip_fail: false
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200778{%- endmacro %}
779
780{%- macro MACRO_CONFIG_DAY01_SALT_MINION() %}
781{#######################################}
782- description: Configure salt-minion on {{ HOSTNAME_CFG01 }}
783 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300784 set -ex;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200785 export SALT_MASTER_MINION_ID={{ HOSTNAME_CFG01 }}
786 envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
787 service salt-minion restart
788
789 while true; do
790 salt-key | grep "$SALT_MASTER_MINION_ID" && break
791 sleep 5
792 done
793
794 sleep 5
795
796 for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do
797 salt-key -d $i -y
798 done
799 node_name: {{ HOSTNAME_CFG01 }}
800 retry: {count: 1, delay: 1}
801 skip_fail: false
802{%- endmacro %}
803
804
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300805{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
806{##################################################}
807
808{# Prepare salt services and nodes settings #}
809
sgudz6e797562018-10-22 12:27:09 +0300810- description: '*Workaround* of harcoded host from day01 grains'
811 cmd: salt-key -d cfg01.mcp-day01.local -y
812 node_name: {{ HOSTNAME_CFG01 }}
813 retry: {count: 1, delay: 1}
814 skip_fail: true
815
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300816- description: Run 'linux' formula on cfg01
817 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
818 node_name: {{ HOSTNAME_CFG01 }}
819 retry: {count: 3, delay: 5}
820 skip_fail: false
821
822- description: Run 'openssh' formula on cfg01
823 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300824 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300825 salt --hard-crash --state-output=mixed --state-verbose=False
826 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +0300827 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300828 node_name: {{ HOSTNAME_CFG01 }}
829 retry: {count: 3, delay: 5}
830 skip_fail: false
831
832- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
833 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
834 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
835 node_name: {{ HOSTNAME_CFG01 }}
836 retry: {count: 1, delay: 1}
837 skip_fail: false
838
839- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300840 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 +0300841 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300842 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300843 skip_fail: false
844
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400845{%- if SALT_FORMULAS_REFS != '' %}
846- description: Replace needed formulas to desired version
847 cmd: |
848 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300849 set -x;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400850 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
851 {% set formula = formula_set.split(':') %}
852 {% set formula_name = formula[0] %}
853 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300854 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400855 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
856 pushd {{ formula_dir }} &&
857 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
858 git checkout FETCH_HEAD &&
859 popd &&
860 if [ -d "{{ formula_dir }}" ]; then
861 echo "Going to replace packaged formula {{ formula_name }}" &&
862 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400863 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
864 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400865 else
866 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
867 fi
868 {%- endfor %}
869 node_name: {{ HOSTNAME_CFG01 }}
870 retry: {count: 1, delay: 10}
871 skip_fail: false
872{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300873
874- description: Refresh pillars on salt-master minion
875 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
876 node_name: {{ HOSTNAME_CFG01 }}
877 retry: {count: 1, delay: 5}
878 skip_fail: false
879
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300880- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300881 cmd: reclass-salt --top
882 node_name: {{ HOSTNAME_CFG01 }}
883 retry: {count: 1, delay: 5}
884 skip_fail: false
885
886- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300887 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 +0300888 node_name: {{ HOSTNAME_CFG01 }}
889 retry: {count: 1, delay: 5}
890 skip_fail: false
891
892- description: Configure linux on master
893 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
894 node_name: {{ HOSTNAME_CFG01 }}
895 retry: {count: 1, delay: 5}
896 skip_fail: false
897
898- description: Configure salt.minion on master
899 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
900 -C 'I@salt:master' state.sls salt.minion && sleep 10
901 node_name: {{ HOSTNAME_CFG01 }}
902 retry: {count: 3, delay: 10}
903 skip_fail: false
904
905- description: Run state 'salt' on master (for salt.api, etc)
906 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
907 -C 'I@salt:master' state.sls salt
908 node_name: {{ HOSTNAME_CFG01 }}
909 retry: {count: 3, delay: 10}
910 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +0300911
912- description: Restart salt-api after states
913 cmd: systemctl restart salt-api
914 node_name: {{ HOSTNAME_CFG01 }}
915 retry: {count: 3, delay: 10}
916 skip_fail: false
917
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300918{%- endmacro %}
919
Dennis Dmitriev85559962018-01-30 15:35:51 +0200920{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
921{#################################################################}
922
923- description: Refresh pillars before generating nodes
924 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
925 node_name: {{ HOSTNAME_CFG01 }}
926 retry: {count: 1, delay: 5}
927 skip_fail: false
928
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +0200929- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200930 cmd: |
931 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300932 set -x;
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200933 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
934 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 +0200935 node_name: {{ HOSTNAME_CFG01 }}
936 retry: {count: 1, delay: 5}
937 skip_fail: false
938
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300939- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
940 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
941 -C 'I@salt:master' state.sls reclass
942 node_name: {{ HOSTNAME_CFG01 }}
943 retry: {count: 1, delay: 5}
944 skip_fail: false
945
Dennis Dmitriev85559962018-01-30 15:35:51 +0200946{%- if RERUN_SALTMASTER_STATE %}
947- description: Regenerate salt.master states for the newly uploaded/created model
948 cmd: |
949 # Need to refresh installed formulas that are required in the model
950 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
951 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
952 node_name: {{ HOSTNAME_CFG01 }}
953 retry: {count: 1, delay: 5}
954 skip_fail: false
955{%- endif %}
956
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300957- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +0200958 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300959 node_name: {{ HOSTNAME_CFG01 }}
960 retry: {count: 1, delay: 5}
961 skip_fail: false
962
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300963- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300964 cmd: |
965 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300966 set -x;
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300967 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
968 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
969 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300970 node_name: {{ HOSTNAME_CFG01 }}
971 retry: {count: 1, delay: 5}
972 skip_fail: false
973
974- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300975 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300976 node_name: {{ HOSTNAME_CFG01 }}
977 retry: {count: 1, delay: 5}
978 skip_fail: false
979{%- endmacro %}
980
981
982{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
983{########################################}
984# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +0200985
986- description: Get linux kernel version from all minions
987 cmd: |
988 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
989 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
990 node_name: {{ HOSTNAME_CFG01 }}
991 retry: {count: 5, delay: 10}
992 skip_fail: false
993
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300994- description: Configure linux on other nodes
995 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
996 node_name: {{ HOSTNAME_CFG01 }}
997 retry: {count: 5, delay: 10}
998 skip_fail: false
999
1000- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +03001001 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 +03001002 salt --hard-crash --state-output=mixed --state-verbose=False
1003 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +03001004 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001005 node_name: {{ HOSTNAME_CFG01 }}
1006 retry: {count: 1, delay: 5}
1007 skip_fail: false
1008
1009- description: Configure salt.minion on other nodes
1010 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 +04001011 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001012 node_name: {{ HOSTNAME_CFG01 }}
1013 retry: {count: 3, delay: 15}
1014 skip_fail: false
1015
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001016- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +04001017 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001018 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +04001019 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001020 skip_fail: false
1021
Victor Ryzhenkina06443e2018-03-15 17:25:19 +04001022- description: Update minion information
Dennis Dmitrievea291ee2018-03-16 12:27:43 +02001023 cmd: |
1024 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001025 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 60
Victor Ryzhenkina06443e2018-03-15 17:25:19 +04001026 node_name: {{ HOSTNAME_CFG01 }}
1027 retry: {count: 1, delay: 10}
1028 skip_fail: false
1029
Dennis Dmitriev14183db2018-03-01 15:14:12 +02001030- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
1031 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
1032 node_name: {{ HOSTNAME_CFG01 }}
1033 retry: {count: 1, delay: 10}
1034 skip_fail: false
1035
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001036- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001037 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001038 node_name: {{ HOSTNAME_CFG01 }}
1039 retry: {count: 3, delay: 15}
1040 skip_fail: false
1041
1042- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001043 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001044 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001045 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001046 skip_fail: false
1047
1048- description: Configure ntp and rsyslog on nodes
1049 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
1050 node_name: {{ HOSTNAME_CFG01 }}
1051 retry: {count: 1, delay: 10}
1052 skip_fail: false
Tatyana Leontovich529e4052018-07-09 18:30:48 +03001053
1054- description: Install and configure iptables if it is in pillar
1055 cmd: |
1056 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' match.pillar 'iptables:service' ; then
1057 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' state.sls iptables
1058 fi
1059 node_name: {{ HOSTNAME_CFG01 }}
1060 retry: {count: 1, delay: 10}
1061 skip_fail: false
1062
1063
1064- description: Install and configure logrotate if it is in pillar
1065 cmd: |
1066 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' match.pillar 'logrotate:server' ; then
1067 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' state.sls logrotate
1068 fi
1069 node_name: {{ HOSTNAME_CFG01 }}
1070 retry: {count: 1, delay: 10}
1071 skip_fail: false
1072
1073- description: Install and configure auditd if it is enabled
1074 cmd: |
1075 if salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" match.pillar 'auditd:service'; then
1076 salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" state.sls auditd
1077 fi
1078 node_name: {{ HOSTNAME_CFG01 }}
1079 retry: {count: 1, delay: 10}
1080 skip_fail: false
1081
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02001082{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001083
1084
1085{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
1086{#########################################}
1087
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001088- description: '*Workaround: Load bonding module before call state.linux'
1089 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
1090 node_name: {{ HOSTNAME_CFG01 }}
1091 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +03001092 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001093
1094- description: '*Workaround* install bridge-utils before running linux formula'
1095 # The formula removes default route and then tries to install the package, fails.
1096 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
1097 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
1098 node_name: {{ HOSTNAME_CFG01 }}
1099 retry: {count: 1, delay: 5}
1100 skip_fail: false
1101
1102{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001103
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001104
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001105{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001106{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001107
1108- description: Set k8s deploy parameters
1109 cmd: |
1110 {% for k8s_opt, value in config.k8s_deploy.items() %}
1111 {% if value|string() %}
1112 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
1113 {% endif %}
1114 {% endfor %}
1115 node_name: {{ HOSTNAME_CFG01 }}
1116 retry: {count: 1, delay: 1}
1117 skip_fail: false
1118
1119{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001120
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001121
1122{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
1123{#############################################}
1124- description: Set SL docker images deploy parameters
1125 cmd: |
1126 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
1127 {%- for sl_opt, value in config.sl_deploy.items() %}
1128 {%- if value|string() %}
1129 {%- if OVERRIDES_FILENAME %}
1130 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
1131 {%- else %}
1132 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
1133 {%- endif %}
1134 {%- endif %}
1135 {%- endfor %}
1136 salt '*' saltutil.refresh_pillar;
1137 sleep 10
1138 node_name: {{ HOSTNAME_CFG01 }}
1139 retry: {count: 1, delay: 1}
1140 skip_fail: false
1141{%- endmacro %}
1142
1143
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001144{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001145{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001146
1147{% for ssh in config.underlay.ssh %}
1148{% if ssh["node_name"].startswith("cmp") %}
1149{% set node_hostname = ssh["node_name"].split('.')[0] %}
1150- description: Register compute {{ ssh['node_name'] }}
1151 cmd: |
1152 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
1153 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
1154 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +04001155 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001156 export config_host={{ config.salt.salt_master_host }}
1157 export node_domain={{ DOMAIN_NAME }}
1158 export nodes_os="xenial"
1159 export node_hostname={{ node_hostname }}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001160 export saltversion={{ SALT_VERSION }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001161 set -xe
1162 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
1163 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
1164 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
1165 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
1166
1167 # Add wrapper to apt-get to avoid race conditions
1168 # with cron jobs running 'unattended-upgrades' script
1169 aptget_wrapper() {
1170 local apt_wrapper_timeout=300
1171 local start_time=$(date '+%s')
1172 local fin_time=$((start_time + apt_wrapper_timeout))
1173 while true; do
1174 if (( "$(date '+%s')" > fin_time )); then
1175 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
1176 fi
1177 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
1178 echo "Waiting while another apt/dpkg process releases locks ..."
1179 sleep 30
1180 continue
1181 else
1182 apt-get $@
1183 break
1184 fi
1185 done
1186 }
1187
1188 # Set default salt version
1189 if [ -z "$saltversion" ]; then
Tatyana Leontovich14e201d2018-07-05 13:28:54 +03001190 saltversion="2017.7"
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001191 fi
1192 echo "Using Salt version $saltversion"
1193
1194 echo "Preparing base OS ..."
1195
1196 case "$node_os" in
1197 trusty)
1198 # workaround for old cloud-init only configuring the first iface
1199 iface_config_dir="/etc/network/interfaces"
1200 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
1201
1202 for iface in $ifaces; do
1203 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
1204 done
1205
1206 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1207
1208 # SUGGESTED UPDATE:
1209 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1210 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1211 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1212 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1213 #install_salt_minion_pkg
1214
1215 # DEPRECATED:
1216 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1217 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1218
1219 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
1220 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1221
1222 aptget_wrapper clean
1223 aptget_wrapper update
1224 aptget_wrapper install -y salt-common
1225 aptget_wrapper install -y salt-minion
1226 ;;
1227 xenial)
1228
1229 # workaround for new cloud-init setting all interfaces statically
1230 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
1231
1232 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1233
1234 # SUGGESTED UPDATE:
1235 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1236 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1237 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1238 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1239 #install_salt_minion_pkg
1240
1241 # DEPRECATED:
1242 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1243 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1244
1245 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
1246 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1247
1248 aptget_wrapper clean
1249 aptget_wrapper update
1250 aptget_wrapper install -y salt-minion
1251 ;;
1252 rhel|centos|centos7|centos7|rhel6|rhel7)
1253 yum install -y git
1254 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1255 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1256 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1257 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1258 install_salt_minion_pkg
1259 ;;
1260 *)
1261 msg="OS '$node_os' is not supported."
1262 esac
1263
1264 echo "Configuring Salt minion ..."
1265 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
1266 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
1267
1268 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
1269
1270 sleep 1
1271
1272 echo "Classifying node ..."
1273 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
1274 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1275 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1276 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1277 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1278 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1279
1280 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1281 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1282 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1283 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1284 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1285
1286 if [ "$node_network05_iface" != "" ]; then
1287 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
1288 fi
1289
1290 # find more parameters (every env starting param_)
1291 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
1292 if [ "$more_params" != "" ]; then
1293 echo "Additional params: $more_params"
1294 more_params=", $more_params"
1295 fi
1296
1297 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}}"
1298
1299 sleep 5
1300
1301 salt-call saltutil.sync_all
1302 salt-call mine.flush
1303 salt-call mine.update
1304 node_name: {{ ssh['node_name'] }}
1305 retry: {count: 1, delay: 1}
1306 skip_fail: false
1307{%- endif %}
1308{%- endfor %}
1309
1310- description: Refresh pillars on all minions
1311 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1312 node_name: {{ HOSTNAME_CFG01 }}
1313 retry: {count: 1, delay: 5}
1314 skip_fail: false
1315
1316- description: Sync all salt resources
1317 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1318 node_name: {{ HOSTNAME_CFG01 }}
1319 retry: {count: 1, delay: 5}
1320 skip_fail: false
1321
sgudz160b7302017-12-22 17:01:10 +02001322{%- endmacro %}
sgudz09e9aa92018-04-12 12:31:53 +03001323
1324{%- macro RUN_NEW_TEMPEST() %}
1325{###################################}
1326
1327- description: Upload tempest template
1328 upload:
1329 local_path: {{ config.salt_deploy.templates_dir }}
1330 local_filename: runtest.yml
1331 remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/
1332 node_name: {{ HOSTNAME_CFG01 }}
1333 skip_fail: False
1334
1335- description: Include class with tempest template into cfg node
1336 cmd: |
1337 sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml;
1338 salt 'cfg01*' saltutil.refresh_pillar;
1339 salt 'cfg01*' saltutil.sync_all;
1340 node_name: {{ HOSTNAME_CFG01 }}
1341 retry: {count: 1, delay: 10}
1342 skip_fail: false
1343
Oleksii Butenko2e8e8ee2018-06-21 11:10:13 +03001344- description: Execute salt.minion on config node
1345 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False state.sls salt.minion;
1346 node_name: {{ HOSTNAME_CFG01 }}
1347 retry: {count: 1, delay: 5}
1348 skip_fail: false
1349
1350- description: Test ping
1351 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False test.ping;
1352 node_name: {{ HOSTNAME_CFG01 }}
1353 retry: {count: 1, delay: 5}
1354 skip_fail: false
1355
sgudz09e9aa92018-04-12 12:31:53 +03001356- description: Create flavors for tests
1357 cmd: |
1358 salt 'cfg01*' state.sls nova.client;
1359 node_name: {{ HOSTNAME_CFG01 }}
1360 retry: {count: 1, delay: 5}
1361 skip_fail: false
1362
1363- description: Create networks for tests
1364 cmd: |
1365 salt 'cfg01*' state.sls neutron.client;
1366 node_name: {{ HOSTNAME_CFG01 }}
1367 retry: {count: 1, delay: 5}
1368 skip_fail: false
1369
1370- description: Upload cirros image
1371 cmd: |
1372 salt 'cfg01*' state.sls glance.client;
1373 node_name: {{ HOSTNAME_CFG01 }}
1374 retry: {count: 1, delay: 5}
1375 skip_fail: false
1376
1377- description: Generate tempest config
1378 cmd: |
1379 salt 'cfg01*' state.sls runtest;
1380 node_name: {{ HOSTNAME_CFG01 }}
1381 retry: {count: 1, delay: 5}
1382 skip_fail: false
1383
1384- description: Run tempest from new docker image
1385 cmd: |
Oleksii Butenko71d76f32018-06-05 17:46:34 +03001386 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 +03001387 node_name: {{ HOSTNAME_GTW01 }}
1388 retry: {count: 1, delay: 30}
1389 skip_fail: true
1390
1391- description: Download xml results
1392 download:
1393 remote_path: /root/test/
1394 remote_filename: "report_*.xml"
1395 local_path: {{ os_env('PWD') }}
1396 node_name: {{ HOSTNAME_GTW01 }}
1397 skip_fail: true
1398
1399{%- endmacro %}
Oleksii Butenko5cd0a162018-06-14 18:18:10 +03001400
1401{%- macro INSTALL_DOCKER_ON_GTW() %}
1402{###################################}
1403
1404- description: Install docker.io on gtw
1405 cmd: salt-call cmd.run 'apt-get install docker.io -y'
1406 node_name: {{ HOSTNAME_GTW01 }}
1407 retry: {count: 1, delay: 30}
1408 skip_fail: false
1409
1410- description: Enable forward policy
1411 cmd: iptables --policy FORWARD ACCEPT
1412 node_name: {{ HOSTNAME_GTW01 }}
1413 retry: {count: 1, delay: 30}
1414 skip_fail: false
1415
1416{%- endmacro %}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001417
1418{%- macro MACRO_CHECK_SALT_VERSION_ON_NODES() %}
1419{#####################################################}
1420
1421{%- for ssh in config.underlay.ssh %}
1422 {%- set salt_roles = [] %}
1423 {%- for role in ssh['roles'] %}
1424 {%- if role in config.salt_deploy.salt_roles %}
1425 {%- set _ = salt_roles.append(role) %}
1426 {%- endif %}
1427 {%- endfor %}
1428
1429 {%- if salt_roles %}
1430- description: 'Check salt version is as expected'
1431 cmd: salt-call test.version | grep {{ SALT_VERSION }}
1432 node_name: {{ ssh['node_name'] }}
1433 retry: {count: 1, delay: 1}
1434 skip_fail: false
1435 {%- endif %}
1436
1437{%- endfor %}
1438{%- endmacro %}
1439
1440{%- macro MACRO_CHECK_SALT_VERSION_SERVICES_ON_CFG() %}
1441{#####################################################}
1442
1443- description: 'Check salt-api, salt-master and salt-minion version'
1444 cmd: |
1445 salt-master --version | grep {{ SALT_VERSION }};
1446 salt-minion --version | grep {{ SALT_VERSION }};
1447 salt-api --version | grep {{ SALT_VERSION }};
1448 node_name: {{ HOSTNAME_CFG01 }}
1449 retry: {count: 1, delay: 5}
1450 skip_fail: false
1451
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001452{%- endmacro %}