blob: b7c26889bfe6d136185e82b44c579d3e5e4141eb [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
Tatyana Leontovich47708552018-12-19 16:36:09 +0200723 apt-get install eatmydata -y;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300724 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200725 # Install common packages
726 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200727 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200728 # Restart salt-minion if it was already installed
729 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300730 node_name: {{ ssh['node_name'] }}
731 retry: {count: 1, delay: 1}
732 skip_fail: false
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200733 {%- else %}
734- description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }}
735 cmd: echo "SSH to $(hostname -f) passed"
736 node_name: {{ ssh['node_name'] }}
737 retry: {count: 1, delay: 1}
738 skip_fail: false
739 {%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300740
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200741{%- endfor %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300742
743- description: Accept salt keys from all the nodes
744 cmd: salt-key -A -y
745 node_name: {{ HOSTNAME_CFG01 }}
746 retry: {count: 1, delay: 5}
747 skip_fail: true
748{%- endmacro %}
749
750
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200751{%- macro MACRO_INSTALL_FORMULAS(FORMULA_SERVICES='') %}
752{#######################################################}
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300753- description: Install salt formulas
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200754 cmd: |
755 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300756 set -x;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200757 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
758 which wget > /dev/null || (apt-get update; apt-get install -y wget);
759 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
760 # echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
761 # wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
762 apt-get clean; apt-get update;
763 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
764 declare -a formula_services=({{ FORMULA_SERVICES }});
765 echo -e "\nInstalling all required salt formulas\n";
766 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300767 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200768 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
769 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
770 done;
771 node_name: {{ HOSTNAME_CFG01 }}
772 retry: {count: 1, delay: 1}
773 skip_fail: false
Dennis Dmitriev010f0292018-07-28 23:33:48 +0300774
775- description: Sync all salt resources on salt-master minion
776 cmd: salt-call saltutil.sync_all && sleep 5
777 node_name: {{ HOSTNAME_CFG01 }}
778 retry: {count: 1, delay: 5}
779 skip_fail: false
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200780{%- endmacro %}
781
782{%- macro MACRO_CONFIG_DAY01_SALT_MINION() %}
783{#######################################}
784- description: Configure salt-minion on {{ HOSTNAME_CFG01 }}
785 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300786 set -ex;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200787 export SALT_MASTER_MINION_ID={{ HOSTNAME_CFG01 }}
788 envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
789 service salt-minion restart
790
791 while true; do
792 salt-key | grep "$SALT_MASTER_MINION_ID" && break
793 sleep 5
794 done
795
796 sleep 5
797
798 for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do
799 salt-key -d $i -y
800 done
801 node_name: {{ HOSTNAME_CFG01 }}
802 retry: {count: 1, delay: 1}
803 skip_fail: false
804{%- endmacro %}
805
806
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300807{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
808{##################################################}
809
810{# Prepare salt services and nodes settings #}
811
sgudz6e797562018-10-22 12:27:09 +0300812- description: '*Workaround* of harcoded host from day01 grains'
813 cmd: salt-key -d cfg01.mcp-day01.local -y
814 node_name: {{ HOSTNAME_CFG01 }}
815 retry: {count: 1, delay: 1}
816 skip_fail: true
817
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300818- description: Run 'linux' formula on cfg01
819 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
820 node_name: {{ HOSTNAME_CFG01 }}
821 retry: {count: 3, delay: 5}
822 skip_fail: false
823
824- description: Run 'openssh' formula on cfg01
825 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300826 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300827 salt --hard-crash --state-output=mixed --state-verbose=False
828 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +0300829 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300830 node_name: {{ HOSTNAME_CFG01 }}
831 retry: {count: 3, delay: 5}
832 skip_fail: false
833
834- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
835 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
836 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
837 node_name: {{ HOSTNAME_CFG01 }}
838 retry: {count: 1, delay: 1}
839 skip_fail: false
840
841- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300842 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 +0300843 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300844 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300845 skip_fail: false
846
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400847{%- if SALT_FORMULAS_REFS != '' %}
848- description: Replace needed formulas to desired version
849 cmd: |
850 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300851 set -x;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400852 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
853 {% set formula = formula_set.split(':') %}
854 {% set formula_name = formula[0] %}
855 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300856 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400857 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
858 pushd {{ formula_dir }} &&
859 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
860 git checkout FETCH_HEAD &&
861 popd &&
862 if [ -d "{{ formula_dir }}" ]; then
863 echo "Going to replace packaged formula {{ formula_name }}" &&
864 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400865 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
866 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400867 else
868 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
869 fi
870 {%- endfor %}
871 node_name: {{ HOSTNAME_CFG01 }}
872 retry: {count: 1, delay: 10}
873 skip_fail: false
874{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300875
876- description: Refresh pillars on salt-master minion
877 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
878 node_name: {{ HOSTNAME_CFG01 }}
879 retry: {count: 1, delay: 5}
880 skip_fail: false
881
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300882- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300883 cmd: reclass-salt --top
884 node_name: {{ HOSTNAME_CFG01 }}
885 retry: {count: 1, delay: 5}
886 skip_fail: false
887
888- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300889 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 +0300890 node_name: {{ HOSTNAME_CFG01 }}
891 retry: {count: 1, delay: 5}
892 skip_fail: false
893
894- description: Configure linux on master
895 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
896 node_name: {{ HOSTNAME_CFG01 }}
897 retry: {count: 1, delay: 5}
898 skip_fail: false
899
900- description: Configure salt.minion on master
901 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
902 -C 'I@salt:master' state.sls salt.minion && sleep 10
903 node_name: {{ HOSTNAME_CFG01 }}
904 retry: {count: 3, delay: 10}
905 skip_fail: false
906
907- description: Run state 'salt' on master (for salt.api, etc)
908 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
909 -C 'I@salt:master' state.sls salt
910 node_name: {{ HOSTNAME_CFG01 }}
911 retry: {count: 3, delay: 10}
912 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +0300913
914- description: Restart salt-api after states
915 cmd: systemctl restart salt-api
916 node_name: {{ HOSTNAME_CFG01 }}
917 retry: {count: 3, delay: 10}
918 skip_fail: false
919
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300920{%- endmacro %}
921
Dennis Dmitriev85559962018-01-30 15:35:51 +0200922{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
923{#################################################################}
924
925- description: Refresh pillars before generating nodes
926 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
927 node_name: {{ HOSTNAME_CFG01 }}
928 retry: {count: 1, delay: 5}
929 skip_fail: false
930
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +0200931- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200932 cmd: |
933 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300934 set -x;
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200935 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
936 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 +0200937 node_name: {{ HOSTNAME_CFG01 }}
938 retry: {count: 1, delay: 5}
939 skip_fail: false
940
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300941- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
942 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
943 -C 'I@salt:master' state.sls reclass
944 node_name: {{ HOSTNAME_CFG01 }}
945 retry: {count: 1, delay: 5}
946 skip_fail: false
947
Dennis Dmitriev85559962018-01-30 15:35:51 +0200948{%- if RERUN_SALTMASTER_STATE %}
949- description: Regenerate salt.master states for the newly uploaded/created model
950 cmd: |
951 # Need to refresh installed formulas that are required in the model
952 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
953 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
954 node_name: {{ HOSTNAME_CFG01 }}
955 retry: {count: 1, delay: 5}
956 skip_fail: false
957{%- endif %}
958
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300959- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +0200960 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300961 node_name: {{ HOSTNAME_CFG01 }}
962 retry: {count: 1, delay: 5}
963 skip_fail: false
964
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300965- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300966 cmd: |
967 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300968 set -x;
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300969 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
970 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
971 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300972 node_name: {{ HOSTNAME_CFG01 }}
973 retry: {count: 1, delay: 5}
974 skip_fail: false
975
976- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300977 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300978 node_name: {{ HOSTNAME_CFG01 }}
979 retry: {count: 1, delay: 5}
980 skip_fail: false
981{%- endmacro %}
982
983
984{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
985{########################################}
986# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +0200987
988- description: Get linux kernel version from all minions
989 cmd: |
990 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
991 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
992 node_name: {{ HOSTNAME_CFG01 }}
993 retry: {count: 5, delay: 10}
994 skip_fail: false
995
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300996- description: Configure linux on other nodes
997 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
998 node_name: {{ HOSTNAME_CFG01 }}
999 retry: {count: 5, delay: 10}
1000 skip_fail: false
1001
1002- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +03001003 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 +03001004 salt --hard-crash --state-output=mixed --state-verbose=False
1005 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +03001006 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001007 node_name: {{ HOSTNAME_CFG01 }}
1008 retry: {count: 1, delay: 5}
1009 skip_fail: false
1010
1011- description: Configure salt.minion on other nodes
1012 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 +04001013 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001014 node_name: {{ HOSTNAME_CFG01 }}
1015 retry: {count: 3, delay: 15}
1016 skip_fail: false
1017
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001018- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +04001019 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001020 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +04001021 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001022 skip_fail: false
1023
Victor Ryzhenkina06443e2018-03-15 17:25:19 +04001024- description: Update minion information
Dennis Dmitrievea291ee2018-03-16 12:27:43 +02001025 cmd: |
1026 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001027 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 60
Victor Ryzhenkina06443e2018-03-15 17:25:19 +04001028 node_name: {{ HOSTNAME_CFG01 }}
1029 retry: {count: 1, delay: 10}
1030 skip_fail: false
1031
Dennis Dmitriev14183db2018-03-01 15:14:12 +02001032- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
1033 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
1034 node_name: {{ HOSTNAME_CFG01 }}
1035 retry: {count: 1, delay: 10}
1036 skip_fail: false
1037
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001038- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001039 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001040 node_name: {{ HOSTNAME_CFG01 }}
1041 retry: {count: 3, delay: 15}
1042 skip_fail: false
1043
1044- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001045 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001046 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001047 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001048 skip_fail: false
1049
1050- description: Configure ntp and rsyslog on nodes
1051 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
1052 node_name: {{ HOSTNAME_CFG01 }}
1053 retry: {count: 1, delay: 10}
1054 skip_fail: false
Tatyana Leontovich529e4052018-07-09 18:30:48 +03001055
1056- description: Install and configure iptables if it is in pillar
1057 cmd: |
1058 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' match.pillar 'iptables:service' ; then
1059 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' state.sls iptables
1060 fi
1061 node_name: {{ HOSTNAME_CFG01 }}
1062 retry: {count: 1, delay: 10}
1063 skip_fail: false
1064
1065
1066- description: Install and configure logrotate if it is in pillar
1067 cmd: |
1068 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' match.pillar 'logrotate:server' ; then
1069 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' state.sls logrotate
1070 fi
1071 node_name: {{ HOSTNAME_CFG01 }}
1072 retry: {count: 1, delay: 10}
1073 skip_fail: false
1074
1075- description: Install and configure auditd if it is enabled
1076 cmd: |
1077 if salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" match.pillar 'auditd:service'; then
1078 salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" state.sls auditd
1079 fi
1080 node_name: {{ HOSTNAME_CFG01 }}
1081 retry: {count: 1, delay: 10}
1082 skip_fail: false
1083
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02001084{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001085
1086
1087{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
1088{#########################################}
1089
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001090- description: '*Workaround: Load bonding module before call state.linux'
1091 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
1092 node_name: {{ HOSTNAME_CFG01 }}
1093 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +03001094 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001095
1096- description: '*Workaround* install bridge-utils before running linux formula'
1097 # The formula removes default route and then tries to install the package, fails.
1098 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
1099 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
1100 node_name: {{ HOSTNAME_CFG01 }}
1101 retry: {count: 1, delay: 5}
1102 skip_fail: false
1103
1104{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001105
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001106
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001107{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001108{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001109
1110- description: Set k8s deploy parameters
1111 cmd: |
1112 {% for k8s_opt, value in config.k8s_deploy.items() %}
1113 {% if value|string() %}
1114 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
1115 {% endif %}
1116 {% endfor %}
1117 node_name: {{ HOSTNAME_CFG01 }}
1118 retry: {count: 1, delay: 1}
1119 skip_fail: false
1120
1121{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001122
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001123
1124{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
1125{#############################################}
1126- description: Set SL docker images deploy parameters
1127 cmd: |
1128 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
1129 {%- for sl_opt, value in config.sl_deploy.items() %}
1130 {%- if value|string() %}
1131 {%- if OVERRIDES_FILENAME %}
1132 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
1133 {%- else %}
1134 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
1135 {%- endif %}
1136 {%- endif %}
1137 {%- endfor %}
1138 salt '*' saltutil.refresh_pillar;
1139 sleep 10
1140 node_name: {{ HOSTNAME_CFG01 }}
1141 retry: {count: 1, delay: 1}
1142 skip_fail: false
1143{%- endmacro %}
1144
1145
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001146{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001147{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001148
1149{% for ssh in config.underlay.ssh %}
1150{% if ssh["node_name"].startswith("cmp") %}
1151{% set node_hostname = ssh["node_name"].split('.')[0] %}
1152- description: Register compute {{ ssh['node_name'] }}
1153 cmd: |
1154 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
1155 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
1156 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +04001157 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001158 export config_host={{ config.salt.salt_master_host }}
1159 export node_domain={{ DOMAIN_NAME }}
1160 export nodes_os="xenial"
1161 export node_hostname={{ node_hostname }}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001162 export saltversion={{ SALT_VERSION }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001163 set -xe
1164 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
1165 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
1166 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
1167 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
1168
1169 # Add wrapper to apt-get to avoid race conditions
1170 # with cron jobs running 'unattended-upgrades' script
1171 aptget_wrapper() {
1172 local apt_wrapper_timeout=300
1173 local start_time=$(date '+%s')
1174 local fin_time=$((start_time + apt_wrapper_timeout))
1175 while true; do
1176 if (( "$(date '+%s')" > fin_time )); then
1177 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
1178 fi
1179 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
1180 echo "Waiting while another apt/dpkg process releases locks ..."
1181 sleep 30
1182 continue
1183 else
1184 apt-get $@
1185 break
1186 fi
1187 done
1188 }
1189
1190 # Set default salt version
1191 if [ -z "$saltversion" ]; then
Tatyana Leontovich14e201d2018-07-05 13:28:54 +03001192 saltversion="2017.7"
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001193 fi
1194 echo "Using Salt version $saltversion"
1195
1196 echo "Preparing base OS ..."
1197
1198 case "$node_os" in
1199 trusty)
1200 # workaround for old cloud-init only configuring the first iface
1201 iface_config_dir="/etc/network/interfaces"
1202 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
1203
1204 for iface in $ifaces; do
1205 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
1206 done
1207
1208 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1209
1210 # SUGGESTED UPDATE:
1211 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1212 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1213 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1214 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1215 #install_salt_minion_pkg
1216
1217 # DEPRECATED:
1218 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1219 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1220
1221 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
1222 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1223
1224 aptget_wrapper clean
1225 aptget_wrapper update
1226 aptget_wrapper install -y salt-common
1227 aptget_wrapper install -y salt-minion
1228 ;;
1229 xenial)
1230
1231 # workaround for new cloud-init setting all interfaces statically
1232 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
1233
1234 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1235
1236 # SUGGESTED UPDATE:
1237 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1238 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1239 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1240 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1241 #install_salt_minion_pkg
1242
1243 # DEPRECATED:
1244 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1245 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1246
1247 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
1248 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1249
1250 aptget_wrapper clean
1251 aptget_wrapper update
1252 aptget_wrapper install -y salt-minion
1253 ;;
1254 rhel|centos|centos7|centos7|rhel6|rhel7)
1255 yum install -y git
1256 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1257 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1258 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1259 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1260 install_salt_minion_pkg
1261 ;;
1262 *)
1263 msg="OS '$node_os' is not supported."
1264 esac
1265
1266 echo "Configuring Salt minion ..."
1267 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
1268 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
1269
1270 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
1271
1272 sleep 1
1273
1274 echo "Classifying node ..."
1275 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
1276 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1277 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1278 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1279 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1280 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1281
1282 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1283 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1284 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1285 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1286 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1287
1288 if [ "$node_network05_iface" != "" ]; then
1289 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
1290 fi
1291
1292 # find more parameters (every env starting param_)
1293 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
1294 if [ "$more_params" != "" ]; then
1295 echo "Additional params: $more_params"
1296 more_params=", $more_params"
1297 fi
1298
1299 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}}"
1300
1301 sleep 5
1302
1303 salt-call saltutil.sync_all
1304 salt-call mine.flush
1305 salt-call mine.update
1306 node_name: {{ ssh['node_name'] }}
1307 retry: {count: 1, delay: 1}
1308 skip_fail: false
1309{%- endif %}
1310{%- endfor %}
1311
1312- description: Refresh pillars on all minions
1313 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1314 node_name: {{ HOSTNAME_CFG01 }}
1315 retry: {count: 1, delay: 5}
1316 skip_fail: false
1317
1318- description: Sync all salt resources
1319 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1320 node_name: {{ HOSTNAME_CFG01 }}
1321 retry: {count: 1, delay: 5}
1322 skip_fail: false
1323
sgudz160b7302017-12-22 17:01:10 +02001324{%- endmacro %}
sgudz09e9aa92018-04-12 12:31:53 +03001325
1326{%- macro RUN_NEW_TEMPEST() %}
1327{###################################}
1328
1329- description: Upload tempest template
1330 upload:
1331 local_path: {{ config.salt_deploy.templates_dir }}
1332 local_filename: runtest.yml
1333 remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/
1334 node_name: {{ HOSTNAME_CFG01 }}
1335 skip_fail: False
1336
1337- description: Include class with tempest template into cfg node
1338 cmd: |
1339 sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml;
1340 salt 'cfg01*' saltutil.refresh_pillar;
1341 salt 'cfg01*' saltutil.sync_all;
1342 node_name: {{ HOSTNAME_CFG01 }}
1343 retry: {count: 1, delay: 10}
1344 skip_fail: false
1345
Oleksii Butenko2e8e8ee2018-06-21 11:10:13 +03001346- description: Execute salt.minion on config node
1347 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False state.sls salt.minion;
1348 node_name: {{ HOSTNAME_CFG01 }}
1349 retry: {count: 1, delay: 5}
1350 skip_fail: false
1351
1352- description: Test ping
1353 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False test.ping;
1354 node_name: {{ HOSTNAME_CFG01 }}
1355 retry: {count: 1, delay: 5}
1356 skip_fail: false
1357
sgudz09e9aa92018-04-12 12:31:53 +03001358- description: Create flavors for tests
1359 cmd: |
1360 salt 'cfg01*' state.sls nova.client;
1361 node_name: {{ HOSTNAME_CFG01 }}
1362 retry: {count: 1, delay: 5}
1363 skip_fail: false
1364
1365- description: Create networks for tests
1366 cmd: |
1367 salt 'cfg01*' state.sls neutron.client;
1368 node_name: {{ HOSTNAME_CFG01 }}
1369 retry: {count: 1, delay: 5}
1370 skip_fail: false
1371
1372- description: Upload cirros image
1373 cmd: |
1374 salt 'cfg01*' state.sls glance.client;
1375 node_name: {{ HOSTNAME_CFG01 }}
1376 retry: {count: 1, delay: 5}
1377 skip_fail: false
1378
1379- description: Generate tempest config
1380 cmd: |
1381 salt 'cfg01*' state.sls runtest;
1382 node_name: {{ HOSTNAME_CFG01 }}
1383 retry: {count: 1, delay: 5}
1384 skip_fail: false
1385
1386- description: Run tempest from new docker image
1387 cmd: |
Oleksii Butenko71d76f32018-06-05 17:46:34 +03001388 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 +03001389 node_name: {{ HOSTNAME_GTW01 }}
1390 retry: {count: 1, delay: 30}
1391 skip_fail: true
1392
1393- description: Download xml results
1394 download:
1395 remote_path: /root/test/
1396 remote_filename: "report_*.xml"
1397 local_path: {{ os_env('PWD') }}
1398 node_name: {{ HOSTNAME_GTW01 }}
1399 skip_fail: true
1400
1401{%- endmacro %}
Oleksii Butenko5cd0a162018-06-14 18:18:10 +03001402
1403{%- macro INSTALL_DOCKER_ON_GTW() %}
1404{###################################}
1405
1406- description: Install docker.io on gtw
1407 cmd: salt-call cmd.run 'apt-get install docker.io -y'
1408 node_name: {{ HOSTNAME_GTW01 }}
1409 retry: {count: 1, delay: 30}
1410 skip_fail: false
1411
1412- description: Enable forward policy
1413 cmd: iptables --policy FORWARD ACCEPT
1414 node_name: {{ HOSTNAME_GTW01 }}
1415 retry: {count: 1, delay: 30}
1416 skip_fail: false
1417
1418{%- endmacro %}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001419
1420{%- macro MACRO_CHECK_SALT_VERSION_ON_NODES() %}
1421{#####################################################}
1422
1423{%- for ssh in config.underlay.ssh %}
1424 {%- set salt_roles = [] %}
1425 {%- for role in ssh['roles'] %}
1426 {%- if role in config.salt_deploy.salt_roles %}
1427 {%- set _ = salt_roles.append(role) %}
1428 {%- endif %}
1429 {%- endfor %}
1430
1431 {%- if salt_roles %}
1432- description: 'Check salt version is as expected'
1433 cmd: salt-call test.version | grep {{ SALT_VERSION }}
1434 node_name: {{ ssh['node_name'] }}
1435 retry: {count: 1, delay: 1}
1436 skip_fail: false
1437 {%- endif %}
1438
1439{%- endfor %}
1440{%- endmacro %}
1441
1442{%- macro MACRO_CHECK_SALT_VERSION_SERVICES_ON_CFG() %}
1443{#####################################################}
1444
1445- description: 'Check salt-api, salt-master and salt-minion version'
1446 cmd: |
1447 salt-master --version | grep {{ SALT_VERSION }};
1448 salt-minion --version | grep {{ SALT_VERSION }};
1449 salt-api --version | grep {{ SALT_VERSION }};
1450 node_name: {{ HOSTNAME_CFG01 }}
1451 retry: {count: 1, delay: 5}
1452 skip_fail: false
1453
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001454{%- endmacro %}