blob: bfa601a421e2a70a6d74e7841323b3b688ff55da [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') %}
Dennis Dmitrievcf777802018-02-14 18:09:55 +020023{% set FORMULA_REPOSITORY = os_env('FORMULA_REPOSITORY', 'deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME} ' + REPOSITORY_SUITE + ' salt extra') %}
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020024{% set FORMULA_GPG = os_env('FORMULA_GPG', 'http://apt.mirantis.com/public.gpg') %}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +030025#{# set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME}/salt/2016.3 " + REPOSITORY_SUITE + " main") #}
26# Note repo is changed so new one looks like defined bellow
27{% 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 +020028{% set SALT_GPG = os_env('SALT_GPG', 'http://apt.mirantis.com/public.gpg') %}
29{% set UBUNTU_REPOSITORY = os_env('UBUNTU_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME} main restricted universe") %}
30{% 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") %}
31{% 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 +030032{% set UBUNTU_KEY_SERVER = os_env('UBUNTU_KEY_SERVER', 'keyserver.ubuntu.com') %}
Tatyana Leontovich908ab932018-04-27 01:25:09 +030033{% set UBUNTU_KEY_ID = os_env('UBUNTU_KEY_ID', '0E08A149DE57BFBE') %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +030034
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020035{# Address pools for reclass cluster model are taken in the following order:
36 # 1. environment variables,
37 # 2. config.underlay.address_pools based on fuel-devops address pools
38 # (see generated '.ini' file after underlay is created),
39 # 3. defaults #}
40{% set address_pools = config.underlay.address_pools %}
41{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
42{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
43{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
44{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
45{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
46{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
47{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
48{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
49
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040050{# Format for formula replacement:
51 # space separated string:
52 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
53
54{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
Tatyana Leontovich1c101312018-04-18 20:33:08 +030055{% set TEMPEST_PATTERN = os_env('TEMPEST_PATTERN', 'tempest') %}
Tatyana Leontovich69700712018-04-23 12:26:57 +030056{% set EXCLUDE_TEST_ARGS = os_env('EXCLUDE_TEST_ARGS', '') %}
Dennis Dmitriev0f272312018-10-01 13:29:40 +030057{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.com/salt-formulas') %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040058
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040059# Needed for using different models in different templates
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020060{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040061
Dennis Dmitriev492813e2017-08-09 15:08:58 +030062
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020063{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
64{#####################################################}
65
66- description: 'Configure key on nodes and install packages'
67 cmd: |
68 rm -rf trusted* ;
69 rm -rf /etc/apt/sources.list ;
Dennis Dmitrievcf777802018-02-14 18:09:55 +020070 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020071 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
72 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
73 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +030074 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020075 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
76 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
77 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
Dennis Dmitrievf4e6efc2018-03-26 06:15:10 -050078 eatmydata apt-get clean;
79 apt-get update;
Dennis Dmitriev01d5e372018-03-15 23:29:29 +020080 sync;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020081 node_name: {{ NODE_NAME }}
82 retry: {count: 1, delay: 5}
83 skip_fail: false
84
85{%- endmacro %}
86
87
Dennis Dmitriev492813e2017-08-09 15:08:58 +030088{%- macro MACRO_INSTALL_SALT_MASTER() %}
89{######################################}
90- description: Installing salt master on cfg01
Dennis Dmitrievcf777802018-02-14 18:09:55 +020091 cmd: |
92 which wget >/dev/null || (apt-get update; apt-get install -y wget);
93 # Configure ubuntu and salt repositories
94 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
95 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
96 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
97 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
98
99 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
100 wget -O - {{ FORMULA_GPG }} | apt-key add -;
101 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300102 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
103
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200104
105 apt-get clean
106 apt-get update
107
108 # Install salt-master and reclass
109 eatmydata apt-get install -y --allow-unauthenticated reclass salt-master
110 # Install common packages
Dennis Dmitrievf88fc7d2018-02-20 15:40:08 +0200111 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 +0200112 sync;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300113 node_name: {{ HOSTNAME_CFG01 }}
114 retry: {count: 1, delay: 1}
115 skip_fail: false
116
Dennis Dmitrievda9be462018-01-24 21:20:09 +0200117- description: Remove any existing minion keys
118 cmd: salt-key -y -D || true
119 node_name: {{ HOSTNAME_CFG01 }}
120 retry: {count: 1, delay: 1}
121 skip_fail: false
122
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300123- description: Configure salt-master on cfg01
124 cmd: |
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200125 cat << 'EOF' > /etc/salt/master.d/master.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300126 file_roots:
127 base:
128 - /usr/share/salt-formulas/env
129 pillar_opts: False
130 open_mode: True
131 reclass: &reclass
132 storage_type: yaml_fs
133 inventory_base_uri: /srv/salt/reclass
134 ext_pillar:
135 - reclass: *reclass
136 master_tops:
137 reclass: *reclass
138 EOF
139 node_name: {{ HOSTNAME_CFG01 }}
140 retry: {count: 1, delay: 1}
141 skip_fail: false
142
143- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300144 cmd: |
145 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200146 #touch /root/.git_trusted_certs.pem;
147 #for server in github.com; do \
148 # openssl s_client -showcerts -connect $server:443 </dev/null \
149 # | openssl x509 -outform PEM \
150 # >> /root/.git_trusted_certs.pem;
151 #done;
152 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
153 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
154 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300155 node_name: {{ HOSTNAME_CFG01 }}
156 retry: {count: 1, delay: 1}
157 skip_fail: false
158{%- endmacro %}
159
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200160
161{%- macro MACRO_CONFIG_DAY01_SALT_MASTER() %}
162{######################################}
163
164- description: Remove /etc/update-motd.d/52-info
165 cmd: rm -vf /etc/update-motd.d/52-info
166 node_name: {{ HOSTNAME_CFG01 }}
167 retry: {count: 1, delay: 10}
168 skip_fail: false
169
170- description: Set up static interface config
171 cmd: |
172 kill $(pidof /sbin/dhclient) || /bin/true
173 cat << 'EOF' > /etc/network/interfaces
174 # This file describes the network interfaces available on your system
175 # and how to activate them. For more information, see interfaces(5).
176
177 # The loopback network interface
178 auto lo
179 iface lo inet loopback
180
181 # The primary network interface
182 auto ens3
183 iface ens3 inet static
184 address {{ IPV4_NET_ADMIN_PREFIX }}.90
185 netmask 255.255.255.0
186 gateway {{ IPV4_NET_ADMIN_PREFIX }}.1
187 EOF
188 node_name: {{ HOSTNAME_CFG01 }}
189 retry: {count: 1, delay: 10}
190 skip_fail: false
191
192- description: Install common packages on cfg01
193 cmd: eatmydata apt-get update && apt-get install -y python-pip git curl at tmux byobu iputils-ping traceroute htop tree wget jq ntpdate
194 node_name: {{ HOSTNAME_CFG01 }}
195 retry: {count: 1, delay: 1}
196 skip_fail: false
197
198- description: Remove any existing minion keys
199 cmd: salt-key -y -D || true
200 node_name: {{ HOSTNAME_CFG01 }}
201 retry: {count: 1, delay: 1}
202 skip_fail: false
203
204- description: Configure GIT settings and certificates
205 cmd: |
206 set -e;
207 #touch /root/.git_trusted_certs.pem;
208 #for server in github.com; do \
209 # openssl s_client -showcerts -connect $server:443 </dev/null \
210 # | openssl x509 -outform PEM \
211 # >> /root/.git_trusted_certs.pem;
212 #done;
213 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
214 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
215 HOME=/root git config --global user.name "MCP Integration QA";
216 node_name: {{ HOSTNAME_CFG01 }}
217 retry: {count: 1, delay: 1}
218 skip_fail: false
219{%- endmacro %}
220
221
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300222{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false, WITH_MAAS=false) %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300223{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300224{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
225
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300226- description: Clone reclass models with submodules
227 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300228 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200229 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200230 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200231
232 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
233 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 +0200234 rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200235
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200236 pushd /srv/salt/reclass;
237 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
238 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200239 {%- if SALT_MODELS_REF_CHANGE != '' %}
240 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200241 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200242 {%- endfor %}
243 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200244 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200245 {%- endif %}
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300246
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300247 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300248 pushd classes/system/ && \
249 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200250 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300251 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200252 popd;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300253 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
254 pushd classes/system/;
255 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
256 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300257 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
258 pushd classes/system/;
259 git fetch --all --tags --prune
260 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
261 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200262 {%- endif %}
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300263
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200264 popd;
265 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300266 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200267
268 # Replace firstly to an intermediate value to avoid intersection between
269 # already replaced and replacing networks.
270 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
271 # 192.168.10 -> 10.16.0 (generated network for admin)
272 # 10.16.0 -> <external network>
273 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300274 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200275 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10/==IPV4_NET_ADMIN_PREFIX==/g' {} +
276 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10/==IPV4_NET_CONTROL_PREFIX==/g' {} +
277 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0/==IPV4_NET_TENANT_PREFIX==/g' {} +
278 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Tatyana Leontovich26756912018-06-06 20:11:05 +0300279 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.60\.0/==IPV4_NET_CONTROL_PREFIX==/g' {} +
280 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.70\.0/==IPV4_NET_ADMIN_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200281
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200282 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
283 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
284 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
285 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 +0200286
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300287 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 +0200288
Tatyana Leontovicha4a96b22018-04-25 14:30:24 +0300289 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300290 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300291 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 +0300292 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 +0300293 {%- endif %}
294
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200295 # Override some context parameters
296 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
297 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
298 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
299
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200300 # Create the cfg01 inventory file or use existing
301 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
302 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300303 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400304 - cluster.{{ CLUSTER_NAME }}.infra.config
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300305 {%- if WITH_MAAS %}
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200306 - cluster.{{ CLUSTER_NAME }}.infra.maas
307 - cluster.{{ CLUSTER_NAME }}.infra.maas-machines
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300308 {%- endif %}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300309 parameters:
310 _param:
311 linux_system_codename: xenial
312 reclass_data_revision: master
313 linux:
314 system:
315 name: cfg01
316 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200317 reclass:
318 storage:
319 data_source:
320 engine: local
321 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300322
323 # Show the changes to the console
324 cd /srv/salt/reclass/; git diff
325 node_name: {{ HOSTNAME_CFG01 }}
326 retry: {count: 1, delay: 1}
327 skip_fail: false
328{%- endmacro %}
329
330
sgudz160b7302017-12-22 17:01:10 +0200331{%- 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 +0300332{###################################################################}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300333{%- set CLUSTER_CONTEXT_PATH = '/root/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200334- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300335 upload:
336 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
337 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300338 remote_path: /root/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300339 node_name: {{ HOSTNAME_CFG01 }}
340
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300341- description: "Show options enabled in the context file for model generation"
342 cmd: |
343 echo "===== Options enabled in the context for generation the model {{ LAB_CONFIG_NAME }} ====="
344 fgrep "True" {{ CLUSTER_CONTEXT_PATH }}
345 echo "===== Sources for model generation ====="
346 echo "# mcp_version: {{ REPOSITORY_SUITE }}"
347 echo "COOKIECUTTER_TEMPLATES_REPOSITORY={{ COOKIECUTTER_TEMPLATES_REPOSITORY }}"
348 {%- if CLUSTER_PRODUCT_MODELS != '' %}
349 echo "CLUSTER_PRODUCT_MODELS={{ CLUSTER_PRODUCT_MODELS }}"
350 {%- endif %}
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300351 {%- if COOKIECUTTER_REF_CHANGE != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300352 echo "COOKIECUTTER_REF_CHANGE={{ COOKIECUTTER_REF_CHANGE }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300353 {%- elif COOKIECUTTER_TEMPLATE_COMMIT != '' %}
354 echo "COOKIECUTTER_TEMPLATE_COMMIT={{ COOKIECUTTER_TEMPLATE_COMMIT }}"
Dennis Dmitriev713dce22018-07-03 11:47:46 +0300355 {%- elif COOKIECUTTER_TAG != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300356 echo "COOKIECUTTER_TAG={{ COOKIECUTTER_TAG }}"
357 {%- endif %}
358 echo "SALT_MODELS_SYSTEM_REPOSITORY={{ SALT_MODELS_SYSTEM_REPOSITORY }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300359 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300360 echo "SALT_MODELS_SYSTEM_REF_CHANGE={{ SALT_MODELS_SYSTEM_REF_CHANGE }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300361 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
362 echo "SALT_MODELS_SYSTEM_COMMIT={{ SALT_MODELS_SYSTEM_COMMIT }}"
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300363 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
364 echo "SALT_MODELS_SYSTEM_TAG={{ SALT_MODELS_SYSTEM_TAG }}"
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300365 {%- endif %}
366 echo "======================================="
367 node_name: {{ HOSTNAME_CFG01 }}
368 retry: {count: 1, delay: 1}
369 skip_fail: false
370
Dennis Dmitriev06979442018-10-24 18:53:49 +0300371- description: "Upload {{ COOKIECUTTER_TEMPLATES_REPOSITORY_USER }} key"
372 upload:
373 local_path: {{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | dirname }}/
374 local_filename: {{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
375 remote_path: /tmp/
376 node_name: {{ HOSTNAME_CFG01 }}
377
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300378- description: Create cluster model from cookiecutter templates
379 cmd: |
380 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300381 set -x;
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300382 sudo apt-get install python-setuptools -y
Dennis Dmitrievb4b74032018-12-18 21:53:23 +0200383
384 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
385 . /root/venv-reclass-tools/bin/activate;
386 pip install -U pip
387
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300388 pip install cookiecutter
Dennis Dmitriev06979442018-10-24 18:53:49 +0300389
390 chmod 0600 /tmp/{{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
391 eval $(ssh-agent)
392 ssh-add /tmp/{{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300393 export GIT_SSL_NO_VERIFY=true; git clone {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} /root/cookiecutter-templates
sgudz4d816eb2017-11-13 11:58:05 +0200394
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300395 {%- if COOKIECUTTER_REF_CHANGE != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300396 pushd /root/cookiecutter-templates
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300397 git fetch {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
sgudz4d816eb2017-11-13 11:58:05 +0200398 popd
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300399 {%- elif COOKIECUTTER_TEMPLATE_COMMIT != '' %}
400 pushd /root/cookiecutter-templates
401 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
402 popd
Dennis Dmitriev713dce22018-07-03 11:47:46 +0300403 {%- elif COOKIECUTTER_TAG != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300404 pushd /root/cookiecutter-templates
Tatyana Leontovich819a6c82018-06-04 12:05:16 +0300405 git fetch --all --tags --prune
406 git checkout tags/{{ COOKIECUTTER_TAG }}
407 popd
408 {%- endif %}
409
Dennis Dmitrievddcea2f2018-12-18 21:21:11 +0200410 if [ -f /root/cookiecutter-templates/requirements.txt ]; then
411 pip install -r /root/cookiecutter-templates/requirements.txt
412 fi
413
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300414 mkdir -p /srv/salt/reclass/classes/cluster/
415 mkdir -p /srv/salt/reclass/classes/system/
416 mkdir -p /srv/salt/reclass/classes/service/
417 mkdir -p /srv/salt/reclass/nodes/_generated
418
419 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200420 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
421 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200422 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300423 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200424 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300425 {%- endif %}
426 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200427 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300428 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300429
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300430 # Replace firstly to an intermediate value to avoid intersection between
431 # already replaced and replacing networks.
432 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
433 # 192.168.10 -> 10.16.0 (generated network for admin)
434 # 10.16.0 -> <external network>
435 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300436 export REPLACE_DIRS="{{ CLUSTER_CONTEXT_PATH }} /root/cookiecutter-templates"
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300437 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
438 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
439 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
440 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300441
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300442 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
443 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
444 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
445 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 +0300446
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300447 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /root/cookiecutter-templates/cluster_product/)' %}
sgudz160b7302017-12-22 17:01:10 +0200448 for item in {{ items }}; do
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300449 python /root/cookiecutter-templates/generate.py \
450 --template /root/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300451 --config-file {{ CLUSTER_CONTEXT_PATH }} \
452 --output-dir /srv/salt/reclass/classes/cluster/;
453 done
454
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300455 export GIT_SSL_NO_VERIFY=true; git clone {{ SALT_MODELS_SYSTEM_REPOSITORY }} /srv/salt/reclass/classes/system/
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300456
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200457 # Create the cfg01 inventory file or use existing
458 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
459 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300460 classes:
461 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200462 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300463 EOF
464
465 node_name: {{ HOSTNAME_CFG01 }}
466 retry: {count: 1, delay: 1}
467 skip_fail: false
468
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300469- description: Modify generated model and reclass-system if necessary
470 cmd: |
471 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300472 set -x;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300473 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300474 pushd /srv/salt/reclass/classes/system/ && \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300475 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300476 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300477 {%- endfor %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300478 popd;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300479 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
480 pushd /srv/salt/reclass/classes/system/
481 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
482 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300483 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
484 pushd /srv/salt/reclass/classes/system/
485 git fetch --all --tags --prune
486 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
487 popd;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300488 {%- endif %}
489
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300490 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200491 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300492 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
493 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
494 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
495 {%- endif %}
496
497 node_name: {{ HOSTNAME_CFG01 }}
498 retry: {count: 1, delay: 1}
499 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +0300500
501- description: Restart salt-api
502 cmd: |
503 set -e;
504 systemctl restart salt-api
505
506 node_name: {{ HOSTNAME_CFG01 }}
507 retry: {count: 1, delay: 1}
508 skip_fail: false
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300509{%- endmacro %}
510
511
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300512{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
513{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300514
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200515- description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300516 cmd: |
517 set -e;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300518 mkdir -p /root/environment/;
519 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 +0300520
Vladimir Khlyunevf337c902018-12-06 12:29:24 +0400521 {%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300522 pushd /root/environment/environment_template &&
sgudzcced67d2017-10-11 15:56:09 +0300523 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
524 git checkout FETCH_HEAD &&
525 popd
Vladimir Khlyunevf337c902018-12-06 12:29:24 +0400526 {%- elif ENVIRONMENT_TEMPLATE_COMMIT != '' %}
527 pushd /root/environment/environment_template
528 git checkout {{ ENVIRONMENT_TEMPLATE_COMMIT }}
529 popd
530 {%- endif %}
531
sgudzcced67d2017-10-11 15:56:09 +0300532 node_name: {{ HOSTNAME_CFG01 }}
533 skip_fail: false
sgudzcced67d2017-10-11 15:56:09 +0300534
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300535{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200536- description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300537 upload:
538 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
539 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300540 remote_path: /root/environment/
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300541 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300542{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300543
Dennis Dmitriev1ddf6472018-11-25 22:30:12 +0200544- description: "Replace template addresses to actual environment addresses"
545 cmd: |
546 set -ex;
547 # Replace firstly to an intermediate value to avoid intersection between
548 # already replaced and replacing networks.
549 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
550 # 192.168.10 -> 10.16.0 (generated network for admin)
551 # 10.16.0 -> <external network>
552 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
553 export REPLACE_DIRS="/root/environment/"
554 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
555 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
556 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
557 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
558
559 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
560 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
561 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
562 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {} +
563 node_name: {{ HOSTNAME_CFG01 }}
564 retry: {count: 1, delay: 5}
565 skip_fail: false
566
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300567- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
568 cmd: |
569 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300570 set -x;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300571 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200572 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
573 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300574 pip install git+https://github.com/dis-xcom/reclass-tools;
575 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
576 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
577 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
578
Dennis Dmitriev6368f082018-02-23 13:30:30 -0500579 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
580 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
581 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 +0300582 fi;
583
584 node_name: {{ HOSTNAME_CFG01 }}
585 retry: {count: 1, delay: 5}
586 skip_fail: false
587
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200588- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300589 cmd: |
590 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200591 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 +0300592
593 node_name: {{ HOSTNAME_CFG01 }}
594 retry: {count: 1, delay: 5}
595 skip_fail: false
596
597- description: "[EXPERIMENTAL] Create environment model for virtual environment"
598 cmd: |
599 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300600 set -x;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200601 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300602 reclass-tools render --template-dir /root/environment/environment_template/ \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300603 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300604 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /root/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300605 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
606 node_name: {{ HOSTNAME_CFG01 }}
607 retry: {count: 1, delay: 5}
608 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300609
610- description: Modify generated model and reclass-system
611 cmd: |
612 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
613 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
614 node_name: {{ HOSTNAME_CFG01 }}
615 retry: {count: 1, delay: 1}
616 skip_fail: false
617
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300618{%- endmacro %}
619
620
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300621{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
622{#######################################################}
623- description: Configure reclass
624 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300625 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300626 set -x;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300627 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300628 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200629 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200630 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
631 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300632 apt-get clean; apt-get update;
633 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
634 declare -a formula_services=({{ FORMULA_SERVICES }});
635 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200636 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300637 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300638 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
639 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
640 done;
641 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
642 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
643 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
644
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200645 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300646 storage_type: yaml_fs
647 pretty_print: True
648 output: yaml
649 inventory_base_uri: /srv/salt/reclass
650 EOF
651 node_name: {{ HOSTNAME_CFG01 }}
652 retry: {count: 1, delay: 1}
653 skip_fail: false
654
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200655- 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 +0300656 cmd: |
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200657 # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top'
658 find /srv/salt/reclass/nodes/ -type f -not -name cfg01.{{ DOMAIN_NAME }}.yml -delete
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300659 node_name: {{ HOSTNAME_CFG01 }}
660 retry: {count: 1, delay: 5}
661 skip_fail: false
662
663- description: Configure salt adoptors on cfg01
664 cmd: |
665 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
666 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
667 node_name: {{ HOSTNAME_CFG01 }}
668 retry: {count: 1, delay: 1}
669 skip_fail: false
670
671- description: Show reclass-salt --top for cfg01 node
672 cmd: reclass-salt --top
673 node_name: {{ HOSTNAME_CFG01 }}
674 retry: {count: 1, delay: 5}
675 skip_fail: false
676
677- description: Restart salt-master service
ibumarskov712a6872018-04-25 09:22:15 +0400678 cmd: service salt-master restart;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300679 node_name: {{ HOSTNAME_CFG01 }}
680 retry: {count: 1, delay: 5}
681 skip_fail: false
682{%- endmacro %}
683
684
685{%- macro MACRO_INSTALL_SALT_MINIONS() %}
686{#######################################}
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200687{%- for ssh in config.underlay.ssh %}
688 {%- set salt_roles = [] %}
689 {%- for role in ssh['roles'] %}
690 {%- if role in config.salt_deploy.salt_roles %}
691 {%- set _ = salt_roles.append(role) %}
692 {%- endif %}
693 {%- endfor %}
694
695 {%- if salt_roles %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300696- description: Configure salt-minion on {{ ssh['node_name'] }}
697 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300698 set -ex;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300699 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitriev3fe24dd2018-07-20 18:38:57 +0300700 cat << EOF > /etc/salt/minion.d/minion.conf
701 id: $(hostname -s).{{ DOMAIN_NAME }}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300702 master: {{ config.salt.salt_master_host }}
703 EOF
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200704
705 # Configure ubuntu and salt repositories
706 which wget >/dev/null || (apt-get update; apt-get install -y wget);
707
708 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
709 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
710 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
711 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
712
713 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300714 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
715
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200716
717 apt-get clean
718 apt-get update
719
720 # Install salt-minion
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300721 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200722 # Install common packages
723 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200724 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200725 # Restart salt-minion if it was already installed
726 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300727 node_name: {{ ssh['node_name'] }}
728 retry: {count: 1, delay: 1}
729 skip_fail: false
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200730 {%- else %}
731- description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }}
732 cmd: echo "SSH to $(hostname -f) passed"
733 node_name: {{ ssh['node_name'] }}
734 retry: {count: 1, delay: 1}
735 skip_fail: false
736 {%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300737
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200738{%- endfor %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300739
740- description: Accept salt keys from all the nodes
741 cmd: salt-key -A -y
742 node_name: {{ HOSTNAME_CFG01 }}
743 retry: {count: 1, delay: 5}
744 skip_fail: true
745{%- endmacro %}
746
747
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200748{%- macro MACRO_INSTALL_FORMULAS(FORMULA_SERVICES='') %}
749{#######################################################}
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300750- description: Install salt formulas
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200751 cmd: |
752 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300753 set -x;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200754 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
755 which wget > /dev/null || (apt-get update; apt-get install -y wget);
756 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
757 # echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
758 # wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
759 apt-get clean; apt-get update;
760 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
761 declare -a formula_services=({{ FORMULA_SERVICES }});
762 echo -e "\nInstalling all required salt formulas\n";
763 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300764 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200765 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
766 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
767 done;
768 node_name: {{ HOSTNAME_CFG01 }}
769 retry: {count: 1, delay: 1}
770 skip_fail: false
Dennis Dmitriev010f0292018-07-28 23:33:48 +0300771
772- description: Sync all salt resources on salt-master minion
773 cmd: salt-call saltutil.sync_all && sleep 5
774 node_name: {{ HOSTNAME_CFG01 }}
775 retry: {count: 1, delay: 5}
776 skip_fail: false
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200777{%- endmacro %}
778
779{%- macro MACRO_CONFIG_DAY01_SALT_MINION() %}
780{#######################################}
781- description: Configure salt-minion on {{ HOSTNAME_CFG01 }}
782 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300783 set -ex;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200784 export SALT_MASTER_MINION_ID={{ HOSTNAME_CFG01 }}
785 envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
786 service salt-minion restart
787
788 while true; do
789 salt-key | grep "$SALT_MASTER_MINION_ID" && break
790 sleep 5
791 done
792
793 sleep 5
794
795 for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do
796 salt-key -d $i -y
797 done
798 node_name: {{ HOSTNAME_CFG01 }}
799 retry: {count: 1, delay: 1}
800 skip_fail: false
801{%- endmacro %}
802
803
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300804{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
805{##################################################}
806
807{# Prepare salt services and nodes settings #}
808
sgudz6e797562018-10-22 12:27:09 +0300809- description: '*Workaround* of harcoded host from day01 grains'
810 cmd: salt-key -d cfg01.mcp-day01.local -y
811 node_name: {{ HOSTNAME_CFG01 }}
812 retry: {count: 1, delay: 1}
813 skip_fail: true
814
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300815- description: Run 'linux' formula on cfg01
816 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
817 node_name: {{ HOSTNAME_CFG01 }}
818 retry: {count: 3, delay: 5}
819 skip_fail: false
820
821- description: Run 'openssh' formula on cfg01
822 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300823 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300824 salt --hard-crash --state-output=mixed --state-verbose=False
825 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +0300826 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300827 node_name: {{ HOSTNAME_CFG01 }}
828 retry: {count: 3, delay: 5}
829 skip_fail: false
830
831- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
832 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
833 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
834 node_name: {{ HOSTNAME_CFG01 }}
835 retry: {count: 1, delay: 1}
836 skip_fail: false
837
838- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300839 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 +0300840 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300841 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300842 skip_fail: false
843
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400844{%- if SALT_FORMULAS_REFS != '' %}
845- description: Replace needed formulas to desired version
846 cmd: |
847 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300848 set -x;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400849 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
850 {% set formula = formula_set.split(':') %}
851 {% set formula_name = formula[0] %}
852 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300853 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400854 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
855 pushd {{ formula_dir }} &&
856 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
857 git checkout FETCH_HEAD &&
858 popd &&
859 if [ -d "{{ formula_dir }}" ]; then
860 echo "Going to replace packaged formula {{ formula_name }}" &&
861 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400862 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
863 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400864 else
865 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
866 fi
867 {%- endfor %}
868 node_name: {{ HOSTNAME_CFG01 }}
869 retry: {count: 1, delay: 10}
870 skip_fail: false
871{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300872
873- description: Refresh pillars on salt-master minion
874 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
875 node_name: {{ HOSTNAME_CFG01 }}
876 retry: {count: 1, delay: 5}
877 skip_fail: false
878
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300879- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300880 cmd: reclass-salt --top
881 node_name: {{ HOSTNAME_CFG01 }}
882 retry: {count: 1, delay: 5}
883 skip_fail: false
884
885- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300886 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 +0300887 node_name: {{ HOSTNAME_CFG01 }}
888 retry: {count: 1, delay: 5}
889 skip_fail: false
890
891- description: Configure linux on master
892 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
893 node_name: {{ HOSTNAME_CFG01 }}
894 retry: {count: 1, delay: 5}
895 skip_fail: false
896
897- description: Configure salt.minion on master
898 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
899 -C 'I@salt:master' state.sls salt.minion && sleep 10
900 node_name: {{ HOSTNAME_CFG01 }}
901 retry: {count: 3, delay: 10}
902 skip_fail: false
903
904- description: Run state 'salt' on master (for salt.api, etc)
905 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
906 -C 'I@salt:master' state.sls salt
907 node_name: {{ HOSTNAME_CFG01 }}
908 retry: {count: 3, delay: 10}
909 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +0300910
911- description: Restart salt-api after states
912 cmd: systemctl restart salt-api
913 node_name: {{ HOSTNAME_CFG01 }}
914 retry: {count: 3, delay: 10}
915 skip_fail: false
916
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300917{%- endmacro %}
918
Dennis Dmitriev85559962018-01-30 15:35:51 +0200919{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
920{#################################################################}
921
922- description: Refresh pillars before generating nodes
923 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
924 node_name: {{ HOSTNAME_CFG01 }}
925 retry: {count: 1, delay: 5}
926 skip_fail: false
927
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +0200928- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200929 cmd: |
930 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300931 set -x;
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200932 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
933 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 +0200934 node_name: {{ HOSTNAME_CFG01 }}
935 retry: {count: 1, delay: 5}
936 skip_fail: false
937
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300938- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
939 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
940 -C 'I@salt:master' state.sls reclass
941 node_name: {{ HOSTNAME_CFG01 }}
942 retry: {count: 1, delay: 5}
943 skip_fail: false
944
Dennis Dmitriev85559962018-01-30 15:35:51 +0200945{%- if RERUN_SALTMASTER_STATE %}
946- description: Regenerate salt.master states for the newly uploaded/created model
947 cmd: |
948 # Need to refresh installed formulas that are required in the model
949 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
950 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
951 node_name: {{ HOSTNAME_CFG01 }}
952 retry: {count: 1, delay: 5}
953 skip_fail: false
954{%- endif %}
955
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300956- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +0200957 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300958 node_name: {{ HOSTNAME_CFG01 }}
959 retry: {count: 1, delay: 5}
960 skip_fail: false
961
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300962- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300963 cmd: |
964 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300965 set -x;
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300966 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
967 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
968 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300969 node_name: {{ HOSTNAME_CFG01 }}
970 retry: {count: 1, delay: 5}
971 skip_fail: false
972
973- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300974 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300975 node_name: {{ HOSTNAME_CFG01 }}
976 retry: {count: 1, delay: 5}
977 skip_fail: false
978{%- endmacro %}
979
980
981{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
982{########################################}
983# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +0200984
985- description: Get linux kernel version from all minions
986 cmd: |
987 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
988 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
989 node_name: {{ HOSTNAME_CFG01 }}
990 retry: {count: 5, delay: 10}
991 skip_fail: false
992
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300993- description: Configure linux on other nodes
994 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
995 node_name: {{ HOSTNAME_CFG01 }}
996 retry: {count: 5, delay: 10}
997 skip_fail: false
998
999- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +03001000 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 +03001001 salt --hard-crash --state-output=mixed --state-verbose=False
1002 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +03001003 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001004 node_name: {{ HOSTNAME_CFG01 }}
1005 retry: {count: 1, delay: 5}
1006 skip_fail: false
1007
1008- description: Configure salt.minion on other nodes
1009 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 +04001010 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001011 node_name: {{ HOSTNAME_CFG01 }}
1012 retry: {count: 3, delay: 15}
1013 skip_fail: false
1014
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001015- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +04001016 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001017 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +04001018 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001019 skip_fail: false
1020
Victor Ryzhenkina06443e2018-03-15 17:25:19 +04001021- description: Update minion information
Dennis Dmitrievea291ee2018-03-16 12:27:43 +02001022 cmd: |
1023 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001024 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 60
Victor Ryzhenkina06443e2018-03-15 17:25:19 +04001025 node_name: {{ HOSTNAME_CFG01 }}
1026 retry: {count: 1, delay: 10}
1027 skip_fail: false
1028
Dennis Dmitriev14183db2018-03-01 15:14:12 +02001029- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
1030 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
1031 node_name: {{ HOSTNAME_CFG01 }}
1032 retry: {count: 1, delay: 10}
1033 skip_fail: false
1034
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001035- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001036 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001037 node_name: {{ HOSTNAME_CFG01 }}
1038 retry: {count: 3, delay: 15}
1039 skip_fail: false
1040
1041- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001042 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001043 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001044 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001045 skip_fail: false
1046
1047- description: Configure ntp and rsyslog on nodes
1048 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
1049 node_name: {{ HOSTNAME_CFG01 }}
1050 retry: {count: 1, delay: 10}
1051 skip_fail: false
Tatyana Leontovich529e4052018-07-09 18:30:48 +03001052
1053- description: Install and configure iptables if it is in pillar
1054 cmd: |
1055 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' match.pillar 'iptables:service' ; then
1056 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' state.sls iptables
1057 fi
1058 node_name: {{ HOSTNAME_CFG01 }}
1059 retry: {count: 1, delay: 10}
1060 skip_fail: false
1061
1062
1063- description: Install and configure logrotate if it is in pillar
1064 cmd: |
1065 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' match.pillar 'logrotate:server' ; then
1066 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' state.sls logrotate
1067 fi
1068 node_name: {{ HOSTNAME_CFG01 }}
1069 retry: {count: 1, delay: 10}
1070 skip_fail: false
1071
1072- description: Install and configure auditd if it is enabled
1073 cmd: |
1074 if salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" match.pillar 'auditd:service'; then
1075 salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" state.sls auditd
1076 fi
1077 node_name: {{ HOSTNAME_CFG01 }}
1078 retry: {count: 1, delay: 10}
1079 skip_fail: false
1080
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02001081{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001082
1083
1084{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
1085{#########################################}
1086
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001087- description: '*Workaround: Load bonding module before call state.linux'
1088 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
1089 node_name: {{ HOSTNAME_CFG01 }}
1090 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +03001091 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001092
1093- description: '*Workaround* install bridge-utils before running linux formula'
1094 # The formula removes default route and then tries to install the package, fails.
1095 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
1096 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
1097 node_name: {{ HOSTNAME_CFG01 }}
1098 retry: {count: 1, delay: 5}
1099 skip_fail: false
1100
1101{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001102
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001103
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001104{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001105{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001106
1107- description: Set k8s deploy parameters
1108 cmd: |
1109 {% for k8s_opt, value in config.k8s_deploy.items() %}
1110 {% if value|string() %}
1111 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
1112 {% endif %}
1113 {% endfor %}
1114 node_name: {{ HOSTNAME_CFG01 }}
1115 retry: {count: 1, delay: 1}
1116 skip_fail: false
1117
1118{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001119
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001120
1121{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
1122{#############################################}
1123- description: Set SL docker images deploy parameters
1124 cmd: |
1125 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
1126 {%- for sl_opt, value in config.sl_deploy.items() %}
1127 {%- if value|string() %}
1128 {%- if OVERRIDES_FILENAME %}
1129 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
1130 {%- else %}
1131 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
1132 {%- endif %}
1133 {%- endif %}
1134 {%- endfor %}
1135 salt '*' saltutil.refresh_pillar;
1136 sleep 10
1137 node_name: {{ HOSTNAME_CFG01 }}
1138 retry: {count: 1, delay: 1}
1139 skip_fail: false
1140{%- endmacro %}
1141
1142
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001143{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001144{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001145
1146{% for ssh in config.underlay.ssh %}
1147{% if ssh["node_name"].startswith("cmp") %}
1148{% set node_hostname = ssh["node_name"].split('.')[0] %}
1149- description: Register compute {{ ssh['node_name'] }}
1150 cmd: |
1151 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
1152 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
1153 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +04001154 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001155 export config_host={{ config.salt.salt_master_host }}
1156 export node_domain={{ DOMAIN_NAME }}
1157 export nodes_os="xenial"
1158 export node_hostname={{ node_hostname }}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001159 export saltversion={{ SALT_VERSION }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001160 set -xe
1161 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
1162 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
1163 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
1164 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
1165
1166 # Add wrapper to apt-get to avoid race conditions
1167 # with cron jobs running 'unattended-upgrades' script
1168 aptget_wrapper() {
1169 local apt_wrapper_timeout=300
1170 local start_time=$(date '+%s')
1171 local fin_time=$((start_time + apt_wrapper_timeout))
1172 while true; do
1173 if (( "$(date '+%s')" > fin_time )); then
1174 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
1175 fi
1176 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
1177 echo "Waiting while another apt/dpkg process releases locks ..."
1178 sleep 30
1179 continue
1180 else
1181 apt-get $@
1182 break
1183 fi
1184 done
1185 }
1186
1187 # Set default salt version
1188 if [ -z "$saltversion" ]; then
Tatyana Leontovich14e201d2018-07-05 13:28:54 +03001189 saltversion="2017.7"
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001190 fi
1191 echo "Using Salt version $saltversion"
1192
1193 echo "Preparing base OS ..."
1194
1195 case "$node_os" in
1196 trusty)
1197 # workaround for old cloud-init only configuring the first iface
1198 iface_config_dir="/etc/network/interfaces"
1199 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
1200
1201 for iface in $ifaces; do
1202 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
1203 done
1204
1205 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1206
1207 # SUGGESTED UPDATE:
1208 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1209 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1210 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1211 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1212 #install_salt_minion_pkg
1213
1214 # DEPRECATED:
1215 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1216 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1217
1218 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
1219 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1220
1221 aptget_wrapper clean
1222 aptget_wrapper update
1223 aptget_wrapper install -y salt-common
1224 aptget_wrapper install -y salt-minion
1225 ;;
1226 xenial)
1227
1228 # workaround for new cloud-init setting all interfaces statically
1229 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
1230
1231 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1232
1233 # SUGGESTED UPDATE:
1234 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1235 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1236 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1237 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1238 #install_salt_minion_pkg
1239
1240 # DEPRECATED:
1241 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1242 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1243
1244 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
1245 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1246
1247 aptget_wrapper clean
1248 aptget_wrapper update
1249 aptget_wrapper install -y salt-minion
1250 ;;
1251 rhel|centos|centos7|centos7|rhel6|rhel7)
1252 yum install -y git
1253 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1254 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1255 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1256 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1257 install_salt_minion_pkg
1258 ;;
1259 *)
1260 msg="OS '$node_os' is not supported."
1261 esac
1262
1263 echo "Configuring Salt minion ..."
1264 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
1265 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
1266
1267 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
1268
1269 sleep 1
1270
1271 echo "Classifying node ..."
1272 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
1273 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1274 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1275 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1276 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1277 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1278
1279 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1280 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1281 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1282 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1283 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1284
1285 if [ "$node_network05_iface" != "" ]; then
1286 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
1287 fi
1288
1289 # find more parameters (every env starting param_)
1290 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
1291 if [ "$more_params" != "" ]; then
1292 echo "Additional params: $more_params"
1293 more_params=", $more_params"
1294 fi
1295
1296 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}}"
1297
1298 sleep 5
1299
1300 salt-call saltutil.sync_all
1301 salt-call mine.flush
1302 salt-call mine.update
1303 node_name: {{ ssh['node_name'] }}
1304 retry: {count: 1, delay: 1}
1305 skip_fail: false
1306{%- endif %}
1307{%- endfor %}
1308
1309- description: Refresh pillars on all minions
1310 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1311 node_name: {{ HOSTNAME_CFG01 }}
1312 retry: {count: 1, delay: 5}
1313 skip_fail: false
1314
1315- description: Sync all salt resources
1316 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1317 node_name: {{ HOSTNAME_CFG01 }}
1318 retry: {count: 1, delay: 5}
1319 skip_fail: false
1320
sgudz160b7302017-12-22 17:01:10 +02001321{%- endmacro %}
sgudz09e9aa92018-04-12 12:31:53 +03001322
1323{%- macro RUN_NEW_TEMPEST() %}
1324{###################################}
1325
1326- description: Upload tempest template
1327 upload:
1328 local_path: {{ config.salt_deploy.templates_dir }}
1329 local_filename: runtest.yml
1330 remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/
1331 node_name: {{ HOSTNAME_CFG01 }}
1332 skip_fail: False
1333
1334- description: Include class with tempest template into cfg node
1335 cmd: |
1336 sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml;
1337 salt 'cfg01*' saltutil.refresh_pillar;
1338 salt 'cfg01*' saltutil.sync_all;
1339 node_name: {{ HOSTNAME_CFG01 }}
1340 retry: {count: 1, delay: 10}
1341 skip_fail: false
1342
Oleksii Butenko2e8e8ee2018-06-21 11:10:13 +03001343- description: Execute salt.minion on config node
1344 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False state.sls salt.minion;
1345 node_name: {{ HOSTNAME_CFG01 }}
1346 retry: {count: 1, delay: 5}
1347 skip_fail: false
1348
1349- description: Test ping
1350 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False test.ping;
1351 node_name: {{ HOSTNAME_CFG01 }}
1352 retry: {count: 1, delay: 5}
1353 skip_fail: false
1354
sgudz09e9aa92018-04-12 12:31:53 +03001355- description: Create flavors for tests
1356 cmd: |
1357 salt 'cfg01*' state.sls nova.client;
1358 node_name: {{ HOSTNAME_CFG01 }}
1359 retry: {count: 1, delay: 5}
1360 skip_fail: false
1361
1362- description: Create networks for tests
1363 cmd: |
1364 salt 'cfg01*' state.sls neutron.client;
1365 node_name: {{ HOSTNAME_CFG01 }}
1366 retry: {count: 1, delay: 5}
1367 skip_fail: false
1368
1369- description: Upload cirros image
1370 cmd: |
1371 salt 'cfg01*' state.sls glance.client;
1372 node_name: {{ HOSTNAME_CFG01 }}
1373 retry: {count: 1, delay: 5}
1374 skip_fail: false
1375
1376- description: Generate tempest config
1377 cmd: |
1378 salt 'cfg01*' state.sls runtest;
1379 node_name: {{ HOSTNAME_CFG01 }}
1380 retry: {count: 1, delay: 5}
1381 skip_fail: false
1382
1383- description: Run tempest from new docker image
1384 cmd: |
Oleksii Butenko71d76f32018-06-05 17:46:34 +03001385 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 +03001386 node_name: {{ HOSTNAME_GTW01 }}
1387 retry: {count: 1, delay: 30}
1388 skip_fail: true
1389
1390- description: Download xml results
1391 download:
1392 remote_path: /root/test/
1393 remote_filename: "report_*.xml"
1394 local_path: {{ os_env('PWD') }}
1395 node_name: {{ HOSTNAME_GTW01 }}
1396 skip_fail: true
1397
1398{%- endmacro %}
Oleksii Butenko5cd0a162018-06-14 18:18:10 +03001399
1400{%- macro INSTALL_DOCKER_ON_GTW() %}
1401{###################################}
1402
1403- description: Install docker.io on gtw
1404 cmd: salt-call cmd.run 'apt-get install docker.io -y'
1405 node_name: {{ HOSTNAME_GTW01 }}
1406 retry: {count: 1, delay: 30}
1407 skip_fail: false
1408
1409- description: Enable forward policy
1410 cmd: iptables --policy FORWARD ACCEPT
1411 node_name: {{ HOSTNAME_GTW01 }}
1412 retry: {count: 1, delay: 30}
1413 skip_fail: false
1414
1415{%- endmacro %}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001416
1417{%- macro MACRO_CHECK_SALT_VERSION_ON_NODES() %}
1418{#####################################################}
1419
1420{%- for ssh in config.underlay.ssh %}
1421 {%- set salt_roles = [] %}
1422 {%- for role in ssh['roles'] %}
1423 {%- if role in config.salt_deploy.salt_roles %}
1424 {%- set _ = salt_roles.append(role) %}
1425 {%- endif %}
1426 {%- endfor %}
1427
1428 {%- if salt_roles %}
1429- description: 'Check salt version is as expected'
1430 cmd: salt-call test.version | grep {{ SALT_VERSION }}
1431 node_name: {{ ssh['node_name'] }}
1432 retry: {count: 1, delay: 1}
1433 skip_fail: false
1434 {%- endif %}
1435
1436{%- endfor %}
1437{%- endmacro %}
1438
1439{%- macro MACRO_CHECK_SALT_VERSION_SERVICES_ON_CFG() %}
1440{#####################################################}
1441
1442- description: 'Check salt-api, salt-master and salt-minion version'
1443 cmd: |
1444 salt-master --version | grep {{ SALT_VERSION }};
1445 salt-minion --version | grep {{ SALT_VERSION }};
1446 salt-api --version | grep {{ SALT_VERSION }};
1447 node_name: {{ HOSTNAME_CFG01 }}
1448 retry: {count: 1, delay: 5}
1449 skip_fail: false
1450
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001451{%- endmacro %}