blob: 775faad20635c25c1fc07156bffb11e5e054c378 [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;
Tatyana Leontovich1ef60952018-12-19 00:36:50 +0200383 sudo apt-get install virtualenv -y
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300384 sudo apt-get install python-setuptools -y
Dennis Dmitrievb4b74032018-12-18 21:53:23 +0200385
386 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
387 . /root/venv-reclass-tools/bin/activate;
388 pip install -U pip
389
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300390 pip install cookiecutter
Dennis Dmitriev06979442018-10-24 18:53:49 +0300391
392 chmod 0600 /tmp/{{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
393 eval $(ssh-agent)
394 ssh-add /tmp/{{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300395 export GIT_SSL_NO_VERIFY=true; git clone {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} /root/cookiecutter-templates
sgudz4d816eb2017-11-13 11:58:05 +0200396
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300397 {%- if COOKIECUTTER_REF_CHANGE != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300398 pushd /root/cookiecutter-templates
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300399 git fetch {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
sgudz4d816eb2017-11-13 11:58:05 +0200400 popd
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300401 {%- elif COOKIECUTTER_TEMPLATE_COMMIT != '' %}
402 pushd /root/cookiecutter-templates
403 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
404 popd
Dennis Dmitriev713dce22018-07-03 11:47:46 +0300405 {%- elif COOKIECUTTER_TAG != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300406 pushd /root/cookiecutter-templates
Tatyana Leontovich819a6c82018-06-04 12:05:16 +0300407 git fetch --all --tags --prune
408 git checkout tags/{{ COOKIECUTTER_TAG }}
409 popd
410 {%- endif %}
411
Dennis Dmitrievddcea2f2018-12-18 21:21:11 +0200412 if [ -f /root/cookiecutter-templates/requirements.txt ]; then
413 pip install -r /root/cookiecutter-templates/requirements.txt
414 fi
415
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300416 mkdir -p /srv/salt/reclass/classes/cluster/
417 mkdir -p /srv/salt/reclass/classes/system/
418 mkdir -p /srv/salt/reclass/classes/service/
419 mkdir -p /srv/salt/reclass/nodes/_generated
420
421 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200422 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
423 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200424 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300425 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200426 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300427 {%- endif %}
428 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200429 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300430 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300431
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300432 # Replace firstly to an intermediate value to avoid intersection between
433 # already replaced and replacing networks.
434 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
435 # 192.168.10 -> 10.16.0 (generated network for admin)
436 # 10.16.0 -> <external network>
437 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300438 export REPLACE_DIRS="{{ CLUSTER_CONTEXT_PATH }} /root/cookiecutter-templates"
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300439 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
440 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
441 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
442 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300443
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300444 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
445 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
446 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
447 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 +0300448
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300449 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /root/cookiecutter-templates/cluster_product/)' %}
sgudz160b7302017-12-22 17:01:10 +0200450 for item in {{ items }}; do
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300451 python /root/cookiecutter-templates/generate.py \
452 --template /root/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300453 --config-file {{ CLUSTER_CONTEXT_PATH }} \
454 --output-dir /srv/salt/reclass/classes/cluster/;
455 done
456
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300457 export GIT_SSL_NO_VERIFY=true; git clone {{ SALT_MODELS_SYSTEM_REPOSITORY }} /srv/salt/reclass/classes/system/
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300458
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200459 # Create the cfg01 inventory file or use existing
460 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
461 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300462 classes:
463 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200464 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300465 EOF
466
467 node_name: {{ HOSTNAME_CFG01 }}
468 retry: {count: 1, delay: 1}
469 skip_fail: false
470
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300471- description: Modify generated model and reclass-system if necessary
472 cmd: |
473 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300474 set -x;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300475 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300476 pushd /srv/salt/reclass/classes/system/ && \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300477 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300478 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300479 {%- endfor %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300480 popd;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300481 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
482 pushd /srv/salt/reclass/classes/system/
483 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
484 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300485 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
486 pushd /srv/salt/reclass/classes/system/
487 git fetch --all --tags --prune
488 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
489 popd;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300490 {%- endif %}
491
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300492 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200493 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300494 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
495 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
496 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
497 {%- endif %}
498
499 node_name: {{ HOSTNAME_CFG01 }}
500 retry: {count: 1, delay: 1}
501 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +0300502
503- description: Restart salt-api
504 cmd: |
505 set -e;
506 systemctl restart salt-api
507
508 node_name: {{ HOSTNAME_CFG01 }}
509 retry: {count: 1, delay: 1}
510 skip_fail: false
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300511{%- endmacro %}
512
513
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300514{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
515{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300516
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200517- description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300518 cmd: |
519 set -e;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300520 mkdir -p /root/environment/;
521 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 +0300522
Vladimir Khlyunevf337c902018-12-06 12:29:24 +0400523 {%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300524 pushd /root/environment/environment_template &&
sgudzcced67d2017-10-11 15:56:09 +0300525 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
526 git checkout FETCH_HEAD &&
527 popd
Vladimir Khlyunevf337c902018-12-06 12:29:24 +0400528 {%- elif ENVIRONMENT_TEMPLATE_COMMIT != '' %}
529 pushd /root/environment/environment_template
530 git checkout {{ ENVIRONMENT_TEMPLATE_COMMIT }}
531 popd
532 {%- endif %}
533
sgudzcced67d2017-10-11 15:56:09 +0300534 node_name: {{ HOSTNAME_CFG01 }}
535 skip_fail: false
sgudzcced67d2017-10-11 15:56:09 +0300536
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300537{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200538- description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300539 upload:
540 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
541 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300542 remote_path: /root/environment/
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300543 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300544{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300545
Dennis Dmitriev1ddf6472018-11-25 22:30:12 +0200546- description: "Replace template addresses to actual environment addresses"
547 cmd: |
548 set -ex;
549 # Replace firstly to an intermediate value to avoid intersection between
550 # already replaced and replacing networks.
551 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
552 # 192.168.10 -> 10.16.0 (generated network for admin)
553 # 10.16.0 -> <external network>
554 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
555 export REPLACE_DIRS="/root/environment/"
556 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
557 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
558 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
559 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
560
561 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
562 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
563 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
564 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {} +
565 node_name: {{ HOSTNAME_CFG01 }}
566 retry: {count: 1, delay: 5}
567 skip_fail: false
568
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300569- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
570 cmd: |
571 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300572 set -x;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300573 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200574 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
575 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300576 pip install git+https://github.com/dis-xcom/reclass-tools;
577 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
578 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
579 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
580
Dennis Dmitriev6368f082018-02-23 13:30:30 -0500581 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
582 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
583 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 +0300584 fi;
585
586 node_name: {{ HOSTNAME_CFG01 }}
587 retry: {count: 1, delay: 5}
588 skip_fail: false
589
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200590- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300591 cmd: |
592 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200593 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 +0300594
595 node_name: {{ HOSTNAME_CFG01 }}
596 retry: {count: 1, delay: 5}
597 skip_fail: false
598
599- description: "[EXPERIMENTAL] Create environment model for virtual environment"
600 cmd: |
601 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300602 set -x;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200603 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300604 reclass-tools render --template-dir /root/environment/environment_template/ \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300605 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300606 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /root/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300607 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
608 node_name: {{ HOSTNAME_CFG01 }}
609 retry: {count: 1, delay: 5}
610 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300611
612- description: Modify generated model and reclass-system
613 cmd: |
614 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
615 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
616 node_name: {{ HOSTNAME_CFG01 }}
617 retry: {count: 1, delay: 1}
618 skip_fail: false
619
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300620{%- endmacro %}
621
622
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300623{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
624{#######################################################}
625- description: Configure reclass
626 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300627 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300628 set -x;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300629 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300630 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200631 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200632 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
633 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300634 apt-get clean; apt-get update;
635 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
636 declare -a formula_services=({{ FORMULA_SERVICES }});
637 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200638 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300639 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300640 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
641 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
642 done;
643 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
644 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
645 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
646
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200647 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300648 storage_type: yaml_fs
649 pretty_print: True
650 output: yaml
651 inventory_base_uri: /srv/salt/reclass
652 EOF
653 node_name: {{ HOSTNAME_CFG01 }}
654 retry: {count: 1, delay: 1}
655 skip_fail: false
656
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200657- 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 +0300658 cmd: |
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200659 # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top'
660 find /srv/salt/reclass/nodes/ -type f -not -name cfg01.{{ DOMAIN_NAME }}.yml -delete
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300661 node_name: {{ HOSTNAME_CFG01 }}
662 retry: {count: 1, delay: 5}
663 skip_fail: false
664
665- description: Configure salt adoptors on cfg01
666 cmd: |
667 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
668 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
669 node_name: {{ HOSTNAME_CFG01 }}
670 retry: {count: 1, delay: 1}
671 skip_fail: false
672
673- description: Show reclass-salt --top for cfg01 node
674 cmd: reclass-salt --top
675 node_name: {{ HOSTNAME_CFG01 }}
676 retry: {count: 1, delay: 5}
677 skip_fail: false
678
679- description: Restart salt-master service
ibumarskov712a6872018-04-25 09:22:15 +0400680 cmd: service salt-master restart;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300681 node_name: {{ HOSTNAME_CFG01 }}
682 retry: {count: 1, delay: 5}
683 skip_fail: false
684{%- endmacro %}
685
686
687{%- macro MACRO_INSTALL_SALT_MINIONS() %}
688{#######################################}
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200689{%- for ssh in config.underlay.ssh %}
690 {%- set salt_roles = [] %}
691 {%- for role in ssh['roles'] %}
692 {%- if role in config.salt_deploy.salt_roles %}
693 {%- set _ = salt_roles.append(role) %}
694 {%- endif %}
695 {%- endfor %}
696
697 {%- if salt_roles %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300698- description: Configure salt-minion on {{ ssh['node_name'] }}
699 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300700 set -ex;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300701 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitriev3fe24dd2018-07-20 18:38:57 +0300702 cat << EOF > /etc/salt/minion.d/minion.conf
703 id: $(hostname -s).{{ DOMAIN_NAME }}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300704 master: {{ config.salt.salt_master_host }}
705 EOF
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200706
707 # Configure ubuntu and salt repositories
708 which wget >/dev/null || (apt-get update; apt-get install -y wget);
709
710 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
711 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
712 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
713 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
714
715 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300716 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
717
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200718
719 apt-get clean
720 apt-get update
721
722 # Install salt-minion
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300723 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200724 # Install common packages
725 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200726 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200727 # Restart salt-minion if it was already installed
728 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300729 node_name: {{ ssh['node_name'] }}
730 retry: {count: 1, delay: 1}
731 skip_fail: false
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200732 {%- else %}
733- description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }}
734 cmd: echo "SSH to $(hostname -f) passed"
735 node_name: {{ ssh['node_name'] }}
736 retry: {count: 1, delay: 1}
737 skip_fail: false
738 {%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300739
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200740{%- endfor %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300741
742- description: Accept salt keys from all the nodes
743 cmd: salt-key -A -y
744 node_name: {{ HOSTNAME_CFG01 }}
745 retry: {count: 1, delay: 5}
746 skip_fail: true
747{%- endmacro %}
748
749
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200750{%- macro MACRO_INSTALL_FORMULAS(FORMULA_SERVICES='') %}
751{#######################################################}
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300752- description: Install salt formulas
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200753 cmd: |
754 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300755 set -x;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200756 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
757 which wget > /dev/null || (apt-get update; apt-get install -y wget);
758 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
759 # echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
760 # wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
761 apt-get clean; apt-get update;
762 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
763 declare -a formula_services=({{ FORMULA_SERVICES }});
764 echo -e "\nInstalling all required salt formulas\n";
765 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300766 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200767 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
768 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
769 done;
770 node_name: {{ HOSTNAME_CFG01 }}
771 retry: {count: 1, delay: 1}
772 skip_fail: false
Dennis Dmitriev010f0292018-07-28 23:33:48 +0300773
774- description: Sync all salt resources on salt-master minion
775 cmd: salt-call saltutil.sync_all && sleep 5
776 node_name: {{ HOSTNAME_CFG01 }}
777 retry: {count: 1, delay: 5}
778 skip_fail: false
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200779{%- endmacro %}
780
781{%- macro MACRO_CONFIG_DAY01_SALT_MINION() %}
782{#######################################}
783- description: Configure salt-minion on {{ HOSTNAME_CFG01 }}
784 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300785 set -ex;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200786 export SALT_MASTER_MINION_ID={{ HOSTNAME_CFG01 }}
787 envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
788 service salt-minion restart
789
790 while true; do
791 salt-key | grep "$SALT_MASTER_MINION_ID" && break
792 sleep 5
793 done
794
795 sleep 5
796
797 for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do
798 salt-key -d $i -y
799 done
800 node_name: {{ HOSTNAME_CFG01 }}
801 retry: {count: 1, delay: 1}
802 skip_fail: false
803{%- endmacro %}
804
805
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300806{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
807{##################################################}
808
809{# Prepare salt services and nodes settings #}
810
sgudz6e797562018-10-22 12:27:09 +0300811- description: '*Workaround* of harcoded host from day01 grains'
812 cmd: salt-key -d cfg01.mcp-day01.local -y
813 node_name: {{ HOSTNAME_CFG01 }}
814 retry: {count: 1, delay: 1}
815 skip_fail: true
816
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300817- description: Run 'linux' formula on cfg01
818 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
819 node_name: {{ HOSTNAME_CFG01 }}
820 retry: {count: 3, delay: 5}
821 skip_fail: false
822
823- description: Run 'openssh' formula on cfg01
824 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300825 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300826 salt --hard-crash --state-output=mixed --state-verbose=False
827 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +0300828 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300829 node_name: {{ HOSTNAME_CFG01 }}
830 retry: {count: 3, delay: 5}
831 skip_fail: false
832
833- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
834 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
835 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
836 node_name: {{ HOSTNAME_CFG01 }}
837 retry: {count: 1, delay: 1}
838 skip_fail: false
839
840- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300841 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 +0300842 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300843 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300844 skip_fail: false
845
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400846{%- if SALT_FORMULAS_REFS != '' %}
847- description: Replace needed formulas to desired version
848 cmd: |
849 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300850 set -x;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400851 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
852 {% set formula = formula_set.split(':') %}
853 {% set formula_name = formula[0] %}
854 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300855 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400856 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
857 pushd {{ formula_dir }} &&
858 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
859 git checkout FETCH_HEAD &&
860 popd &&
861 if [ -d "{{ formula_dir }}" ]; then
862 echo "Going to replace packaged formula {{ formula_name }}" &&
863 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400864 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
865 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400866 else
867 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
868 fi
869 {%- endfor %}
870 node_name: {{ HOSTNAME_CFG01 }}
871 retry: {count: 1, delay: 10}
872 skip_fail: false
873{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300874
875- description: Refresh pillars on salt-master minion
876 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
877 node_name: {{ HOSTNAME_CFG01 }}
878 retry: {count: 1, delay: 5}
879 skip_fail: false
880
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300881- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300882 cmd: reclass-salt --top
883 node_name: {{ HOSTNAME_CFG01 }}
884 retry: {count: 1, delay: 5}
885 skip_fail: false
886
887- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300888 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 +0300889 node_name: {{ HOSTNAME_CFG01 }}
890 retry: {count: 1, delay: 5}
891 skip_fail: false
892
893- description: Configure linux on master
894 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
895 node_name: {{ HOSTNAME_CFG01 }}
896 retry: {count: 1, delay: 5}
897 skip_fail: false
898
899- description: Configure salt.minion on master
900 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
901 -C 'I@salt:master' state.sls salt.minion && sleep 10
902 node_name: {{ HOSTNAME_CFG01 }}
903 retry: {count: 3, delay: 10}
904 skip_fail: false
905
906- description: Run state 'salt' on master (for salt.api, etc)
907 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
908 -C 'I@salt:master' state.sls salt
909 node_name: {{ HOSTNAME_CFG01 }}
910 retry: {count: 3, delay: 10}
911 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +0300912
913- description: Restart salt-api after states
914 cmd: systemctl restart salt-api
915 node_name: {{ HOSTNAME_CFG01 }}
916 retry: {count: 3, delay: 10}
917 skip_fail: false
918
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300919{%- endmacro %}
920
Dennis Dmitriev85559962018-01-30 15:35:51 +0200921{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
922{#################################################################}
923
924- description: Refresh pillars before generating nodes
925 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
926 node_name: {{ HOSTNAME_CFG01 }}
927 retry: {count: 1, delay: 5}
928 skip_fail: false
929
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +0200930- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200931 cmd: |
932 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300933 set -x;
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200934 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
935 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 +0200936 node_name: {{ HOSTNAME_CFG01 }}
937 retry: {count: 1, delay: 5}
938 skip_fail: false
939
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300940- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
941 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
942 -C 'I@salt:master' state.sls reclass
943 node_name: {{ HOSTNAME_CFG01 }}
944 retry: {count: 1, delay: 5}
945 skip_fail: false
946
Dennis Dmitriev85559962018-01-30 15:35:51 +0200947{%- if RERUN_SALTMASTER_STATE %}
948- description: Regenerate salt.master states for the newly uploaded/created model
949 cmd: |
950 # Need to refresh installed formulas that are required in the model
951 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
952 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
953 node_name: {{ HOSTNAME_CFG01 }}
954 retry: {count: 1, delay: 5}
955 skip_fail: false
956{%- endif %}
957
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300958- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +0200959 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300960 node_name: {{ HOSTNAME_CFG01 }}
961 retry: {count: 1, delay: 5}
962 skip_fail: false
963
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300964- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300965 cmd: |
966 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300967 set -x;
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300968 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
969 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
970 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300971 node_name: {{ HOSTNAME_CFG01 }}
972 retry: {count: 1, delay: 5}
973 skip_fail: false
974
975- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300976 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300977 node_name: {{ HOSTNAME_CFG01 }}
978 retry: {count: 1, delay: 5}
979 skip_fail: false
980{%- endmacro %}
981
982
983{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
984{########################################}
985# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +0200986
987- description: Get linux kernel version from all minions
988 cmd: |
989 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
990 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
991 node_name: {{ HOSTNAME_CFG01 }}
992 retry: {count: 5, delay: 10}
993 skip_fail: false
994
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300995- description: Configure linux on other nodes
996 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
997 node_name: {{ HOSTNAME_CFG01 }}
998 retry: {count: 5, delay: 10}
999 skip_fail: false
1000
1001- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +03001002 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 +03001003 salt --hard-crash --state-output=mixed --state-verbose=False
1004 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +03001005 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001006 node_name: {{ HOSTNAME_CFG01 }}
1007 retry: {count: 1, delay: 5}
1008 skip_fail: false
1009
1010- description: Configure salt.minion on other nodes
1011 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 +04001012 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001013 node_name: {{ HOSTNAME_CFG01 }}
1014 retry: {count: 3, delay: 15}
1015 skip_fail: false
1016
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001017- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +04001018 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001019 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +04001020 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001021 skip_fail: false
1022
Victor Ryzhenkina06443e2018-03-15 17:25:19 +04001023- description: Update minion information
Dennis Dmitrievea291ee2018-03-16 12:27:43 +02001024 cmd: |
1025 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001026 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 60
Victor Ryzhenkina06443e2018-03-15 17:25:19 +04001027 node_name: {{ HOSTNAME_CFG01 }}
1028 retry: {count: 1, delay: 10}
1029 skip_fail: false
1030
Dennis Dmitriev14183db2018-03-01 15:14:12 +02001031- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
1032 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
1033 node_name: {{ HOSTNAME_CFG01 }}
1034 retry: {count: 1, delay: 10}
1035 skip_fail: false
1036
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001037- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001038 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001039 node_name: {{ HOSTNAME_CFG01 }}
1040 retry: {count: 3, delay: 15}
1041 skip_fail: false
1042
1043- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001044 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001045 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001046 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001047 skip_fail: false
1048
1049- description: Configure ntp and rsyslog on nodes
1050 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
1051 node_name: {{ HOSTNAME_CFG01 }}
1052 retry: {count: 1, delay: 10}
1053 skip_fail: false
Tatyana Leontovich529e4052018-07-09 18:30:48 +03001054
1055- description: Install and configure iptables if it is in pillar
1056 cmd: |
1057 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' match.pillar 'iptables:service' ; then
1058 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' state.sls iptables
1059 fi
1060 node_name: {{ HOSTNAME_CFG01 }}
1061 retry: {count: 1, delay: 10}
1062 skip_fail: false
1063
1064
1065- description: Install and configure logrotate if it is in pillar
1066 cmd: |
1067 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' match.pillar 'logrotate:server' ; then
1068 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' state.sls logrotate
1069 fi
1070 node_name: {{ HOSTNAME_CFG01 }}
1071 retry: {count: 1, delay: 10}
1072 skip_fail: false
1073
1074- description: Install and configure auditd if it is enabled
1075 cmd: |
1076 if salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" match.pillar 'auditd:service'; then
1077 salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" state.sls auditd
1078 fi
1079 node_name: {{ HOSTNAME_CFG01 }}
1080 retry: {count: 1, delay: 10}
1081 skip_fail: false
1082
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02001083{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001084
1085
1086{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
1087{#########################################}
1088
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001089- description: '*Workaround: Load bonding module before call state.linux'
1090 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
1091 node_name: {{ HOSTNAME_CFG01 }}
1092 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +03001093 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001094
1095- description: '*Workaround* install bridge-utils before running linux formula'
1096 # The formula removes default route and then tries to install the package, fails.
1097 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
1098 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
1099 node_name: {{ HOSTNAME_CFG01 }}
1100 retry: {count: 1, delay: 5}
1101 skip_fail: false
1102
1103{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001104
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001105
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001106{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001107{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001108
1109- description: Set k8s deploy parameters
1110 cmd: |
1111 {% for k8s_opt, value in config.k8s_deploy.items() %}
1112 {% if value|string() %}
1113 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
1114 {% endif %}
1115 {% endfor %}
1116 node_name: {{ HOSTNAME_CFG01 }}
1117 retry: {count: 1, delay: 1}
1118 skip_fail: false
1119
1120{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001121
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001122
1123{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
1124{#############################################}
1125- description: Set SL docker images deploy parameters
1126 cmd: |
1127 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
1128 {%- for sl_opt, value in config.sl_deploy.items() %}
1129 {%- if value|string() %}
1130 {%- if OVERRIDES_FILENAME %}
1131 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
1132 {%- else %}
1133 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
1134 {%- endif %}
1135 {%- endif %}
1136 {%- endfor %}
1137 salt '*' saltutil.refresh_pillar;
1138 sleep 10
1139 node_name: {{ HOSTNAME_CFG01 }}
1140 retry: {count: 1, delay: 1}
1141 skip_fail: false
1142{%- endmacro %}
1143
1144
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001145{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001146{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001147
1148{% for ssh in config.underlay.ssh %}
1149{% if ssh["node_name"].startswith("cmp") %}
1150{% set node_hostname = ssh["node_name"].split('.')[0] %}
1151- description: Register compute {{ ssh['node_name'] }}
1152 cmd: |
1153 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
1154 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
1155 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +04001156 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001157 export config_host={{ config.salt.salt_master_host }}
1158 export node_domain={{ DOMAIN_NAME }}
1159 export nodes_os="xenial"
1160 export node_hostname={{ node_hostname }}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001161 export saltversion={{ SALT_VERSION }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001162 set -xe
1163 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
1164 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
1165 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
1166 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
1167
1168 # Add wrapper to apt-get to avoid race conditions
1169 # with cron jobs running 'unattended-upgrades' script
1170 aptget_wrapper() {
1171 local apt_wrapper_timeout=300
1172 local start_time=$(date '+%s')
1173 local fin_time=$((start_time + apt_wrapper_timeout))
1174 while true; do
1175 if (( "$(date '+%s')" > fin_time )); then
1176 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
1177 fi
1178 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
1179 echo "Waiting while another apt/dpkg process releases locks ..."
1180 sleep 30
1181 continue
1182 else
1183 apt-get $@
1184 break
1185 fi
1186 done
1187 }
1188
1189 # Set default salt version
1190 if [ -z "$saltversion" ]; then
Tatyana Leontovich14e201d2018-07-05 13:28:54 +03001191 saltversion="2017.7"
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001192 fi
1193 echo "Using Salt version $saltversion"
1194
1195 echo "Preparing base OS ..."
1196
1197 case "$node_os" in
1198 trusty)
1199 # workaround for old cloud-init only configuring the first iface
1200 iface_config_dir="/etc/network/interfaces"
1201 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
1202
1203 for iface in $ifaces; do
1204 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
1205 done
1206
1207 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1208
1209 # SUGGESTED UPDATE:
1210 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1211 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1212 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1213 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1214 #install_salt_minion_pkg
1215
1216 # DEPRECATED:
1217 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1218 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1219
1220 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
1221 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1222
1223 aptget_wrapper clean
1224 aptget_wrapper update
1225 aptget_wrapper install -y salt-common
1226 aptget_wrapper install -y salt-minion
1227 ;;
1228 xenial)
1229
1230 # workaround for new cloud-init setting all interfaces statically
1231 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
1232
1233 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1234
1235 # SUGGESTED UPDATE:
1236 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1237 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1238 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1239 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1240 #install_salt_minion_pkg
1241
1242 # DEPRECATED:
1243 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1244 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1245
1246 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
1247 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1248
1249 aptget_wrapper clean
1250 aptget_wrapper update
1251 aptget_wrapper install -y salt-minion
1252 ;;
1253 rhel|centos|centos7|centos7|rhel6|rhel7)
1254 yum install -y git
1255 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1256 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1257 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1258 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1259 install_salt_minion_pkg
1260 ;;
1261 *)
1262 msg="OS '$node_os' is not supported."
1263 esac
1264
1265 echo "Configuring Salt minion ..."
1266 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
1267 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
1268
1269 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
1270
1271 sleep 1
1272
1273 echo "Classifying node ..."
1274 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
1275 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1276 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1277 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1278 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1279 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1280
1281 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1282 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1283 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1284 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1285 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1286
1287 if [ "$node_network05_iface" != "" ]; then
1288 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
1289 fi
1290
1291 # find more parameters (every env starting param_)
1292 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
1293 if [ "$more_params" != "" ]; then
1294 echo "Additional params: $more_params"
1295 more_params=", $more_params"
1296 fi
1297
1298 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}}"
1299
1300 sleep 5
1301
1302 salt-call saltutil.sync_all
1303 salt-call mine.flush
1304 salt-call mine.update
1305 node_name: {{ ssh['node_name'] }}
1306 retry: {count: 1, delay: 1}
1307 skip_fail: false
1308{%- endif %}
1309{%- endfor %}
1310
1311- description: Refresh pillars on all minions
1312 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1313 node_name: {{ HOSTNAME_CFG01 }}
1314 retry: {count: 1, delay: 5}
1315 skip_fail: false
1316
1317- description: Sync all salt resources
1318 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1319 node_name: {{ HOSTNAME_CFG01 }}
1320 retry: {count: 1, delay: 5}
1321 skip_fail: false
1322
sgudz160b7302017-12-22 17:01:10 +02001323{%- endmacro %}
sgudz09e9aa92018-04-12 12:31:53 +03001324
1325{%- macro RUN_NEW_TEMPEST() %}
1326{###################################}
1327
1328- description: Upload tempest template
1329 upload:
1330 local_path: {{ config.salt_deploy.templates_dir }}
1331 local_filename: runtest.yml
1332 remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/
1333 node_name: {{ HOSTNAME_CFG01 }}
1334 skip_fail: False
1335
1336- description: Include class with tempest template into cfg node
1337 cmd: |
1338 sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml;
1339 salt 'cfg01*' saltutil.refresh_pillar;
1340 salt 'cfg01*' saltutil.sync_all;
1341 node_name: {{ HOSTNAME_CFG01 }}
1342 retry: {count: 1, delay: 10}
1343 skip_fail: false
1344
Oleksii Butenko2e8e8ee2018-06-21 11:10:13 +03001345- description: Execute salt.minion on config node
1346 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False state.sls salt.minion;
1347 node_name: {{ HOSTNAME_CFG01 }}
1348 retry: {count: 1, delay: 5}
1349 skip_fail: false
1350
1351- description: Test ping
1352 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False test.ping;
1353 node_name: {{ HOSTNAME_CFG01 }}
1354 retry: {count: 1, delay: 5}
1355 skip_fail: false
1356
sgudz09e9aa92018-04-12 12:31:53 +03001357- description: Create flavors for tests
1358 cmd: |
1359 salt 'cfg01*' state.sls nova.client;
1360 node_name: {{ HOSTNAME_CFG01 }}
1361 retry: {count: 1, delay: 5}
1362 skip_fail: false
1363
1364- description: Create networks for tests
1365 cmd: |
1366 salt 'cfg01*' state.sls neutron.client;
1367 node_name: {{ HOSTNAME_CFG01 }}
1368 retry: {count: 1, delay: 5}
1369 skip_fail: false
1370
1371- description: Upload cirros image
1372 cmd: |
1373 salt 'cfg01*' state.sls glance.client;
1374 node_name: {{ HOSTNAME_CFG01 }}
1375 retry: {count: 1, delay: 5}
1376 skip_fail: false
1377
1378- description: Generate tempest config
1379 cmd: |
1380 salt 'cfg01*' state.sls runtest;
1381 node_name: {{ HOSTNAME_CFG01 }}
1382 retry: {count: 1, delay: 5}
1383 skip_fail: false
1384
1385- description: Run tempest from new docker image
1386 cmd: |
Oleksii Butenko71d76f32018-06-05 17:46:34 +03001387 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 +03001388 node_name: {{ HOSTNAME_GTW01 }}
1389 retry: {count: 1, delay: 30}
1390 skip_fail: true
1391
1392- description: Download xml results
1393 download:
1394 remote_path: /root/test/
1395 remote_filename: "report_*.xml"
1396 local_path: {{ os_env('PWD') }}
1397 node_name: {{ HOSTNAME_GTW01 }}
1398 skip_fail: true
1399
1400{%- endmacro %}
Oleksii Butenko5cd0a162018-06-14 18:18:10 +03001401
1402{%- macro INSTALL_DOCKER_ON_GTW() %}
1403{###################################}
1404
1405- description: Install docker.io on gtw
1406 cmd: salt-call cmd.run 'apt-get install docker.io -y'
1407 node_name: {{ HOSTNAME_GTW01 }}
1408 retry: {count: 1, delay: 30}
1409 skip_fail: false
1410
1411- description: Enable forward policy
1412 cmd: iptables --policy FORWARD ACCEPT
1413 node_name: {{ HOSTNAME_GTW01 }}
1414 retry: {count: 1, delay: 30}
1415 skip_fail: false
1416
1417{%- endmacro %}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001418
1419{%- macro MACRO_CHECK_SALT_VERSION_ON_NODES() %}
1420{#####################################################}
1421
1422{%- for ssh in config.underlay.ssh %}
1423 {%- set salt_roles = [] %}
1424 {%- for role in ssh['roles'] %}
1425 {%- if role in config.salt_deploy.salt_roles %}
1426 {%- set _ = salt_roles.append(role) %}
1427 {%- endif %}
1428 {%- endfor %}
1429
1430 {%- if salt_roles %}
1431- description: 'Check salt version is as expected'
1432 cmd: salt-call test.version | grep {{ SALT_VERSION }}
1433 node_name: {{ ssh['node_name'] }}
1434 retry: {count: 1, delay: 1}
1435 skip_fail: false
1436 {%- endif %}
1437
1438{%- endfor %}
1439{%- endmacro %}
1440
1441{%- macro MACRO_CHECK_SALT_VERSION_SERVICES_ON_CFG() %}
1442{#####################################################}
1443
1444- description: 'Check salt-api, salt-master and salt-minion version'
1445 cmd: |
1446 salt-master --version | grep {{ SALT_VERSION }};
1447 salt-minion --version | grep {{ SALT_VERSION }};
1448 salt-api --version | grep {{ SALT_VERSION }};
1449 node_name: {{ HOSTNAME_CFG01 }}
1450 retry: {count: 1, delay: 5}
1451 skip_fail: false
1452
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001453{%- endmacro %}