blob: e5929948c70253817540e7dded0729b40c551cf1 [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 Dmitrievd9168b52018-12-19 18:53:52 +020023{# set FORMULA_REPOSITORY = os_env('FORMULA_REPOSITORY', 'deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME} ' + REPOSITORY_SUITE + ' salt extra') #}
obutenkob6006352018-12-20 10:46:44 +020024{% set FORMULA_REPOSITORY = os_env('FORMULA_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/salt-formulas"+"/${DISTRIB_CODENAME} ${DISTRIB_CODENAME} main") %}
Dennis Dmitrievd9168b52018-12-19 18:53:52 +020025{# set FORMULA_GPG = os_env('FORMULA_GPG', 'http://apt.mirantis.com/public.gpg') #}
obutenkob6006352018-12-20 10:46:44 +020026{% set FORMULA_GPG = os_env('FORMULA_GPG', "http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/salt-formulas/xenial/archive-salt-formulas.key") %}
Dennis Dmitrievd9168b52018-12-19 18:53:52 +020027{# set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME}/salt/2016.3 " + REPOSITORY_SUITE + " main") #}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +030028# Note repo is changed so new one looks like defined bellow
29{% set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE+ "/saltstack-" + SALT_VERSION+ "/${DISTRIB_CODENAME} ${DISTRIB_CODENAME} main") %}
Dennis Dmitrievd9168b52018-12-19 18:53:52 +020030{# set SALT_GPG = os_env('SALT_GPG', 'http://apt.mirantis.com/public.gpg') #}
obutenkob6006352018-12-20 10:46:44 +020031{% set SALT_GPG = os_env('SALT_GPG', "http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/salt-formulas/xenial/archive-salt-formulas.key") %}
Dennis Dmitrievcf777802018-02-14 18:09:55 +020032{% set UBUNTU_REPOSITORY = os_env('UBUNTU_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME} main restricted universe") %}
33{% 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") %}
34{% 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 +030035{% set UBUNTU_KEY_SERVER = os_env('UBUNTU_KEY_SERVER', 'keyserver.ubuntu.com') %}
Tatyana Leontovich908ab932018-04-27 01:25:09 +030036{% set UBUNTU_KEY_ID = os_env('UBUNTU_KEY_ID', '0E08A149DE57BFBE') %}
sgudzb7953382019-02-18 17:59:30 +020037{% set UPDATE_REPO_CUSTOM_TAG = os_env('UPDATE_REPO_CUSTOM_TAG', '') %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +030038
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020039{# Address pools for reclass cluster model are taken in the following order:
40 # 1. environment variables,
41 # 2. config.underlay.address_pools based on fuel-devops address pools
42 # (see generated '.ini' file after underlay is created),
43 # 3. defaults #}
44{% set address_pools = config.underlay.address_pools %}
45{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
46{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
47{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
48{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
49{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
50{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
51{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
52{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
53
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040054{# Format for formula replacement:
55 # space separated string:
56 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
57
58{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
Tatyana Leontovich1c101312018-04-18 20:33:08 +030059{% set TEMPEST_PATTERN = os_env('TEMPEST_PATTERN', 'tempest') %}
Tatyana Leontovich69700712018-04-23 12:26:57 +030060{% set EXCLUDE_TEST_ARGS = os_env('EXCLUDE_TEST_ARGS', '') %}
Dennis Dmitriev0f272312018-10-01 13:29:40 +030061{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.com/salt-formulas') %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040062
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040063# Needed for using different models in different templates
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020064{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040065
Dennis Dmitriev492813e2017-08-09 15:08:58 +030066
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020067{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
68{#####################################################}
69
70- description: 'Configure key on nodes and install packages'
71 cmd: |
72 rm -rf trusted* ;
73 rm -rf /etc/apt/sources.list ;
Dennis Dmitrievcf777802018-02-14 18:09:55 +020074 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020075 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
76 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
77 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +030078 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020079 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
80 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
81 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
Dennis Dmitrievf4e6efc2018-03-26 06:15:10 -050082 eatmydata apt-get clean;
83 apt-get update;
Dennis Dmitriev01d5e372018-03-15 23:29:29 +020084 sync;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020085 node_name: {{ NODE_NAME }}
86 retry: {count: 1, delay: 5}
87 skip_fail: false
88
89{%- endmacro %}
90
91
Dennis Dmitriev492813e2017-08-09 15:08:58 +030092{%- macro MACRO_INSTALL_SALT_MASTER() %}
93{######################################}
94- description: Installing salt master on cfg01
Dennis Dmitrievcf777802018-02-14 18:09:55 +020095 cmd: |
96 which wget >/dev/null || (apt-get update; apt-get install -y wget);
97 # Configure ubuntu and salt repositories
98 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
99 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
100 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
101 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
102
103 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
104 wget -O - {{ FORMULA_GPG }} | apt-key add -;
105 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300106 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
107
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200108
109 apt-get clean
110 apt-get update
111
112 # Install salt-master and reclass
113 eatmydata apt-get install -y --allow-unauthenticated reclass salt-master
114 # Install common packages
Dennis Dmitrievf88fc7d2018-02-20 15:40:08 +0200115 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 +0200116 sync;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300117 node_name: {{ HOSTNAME_CFG01 }}
118 retry: {count: 1, delay: 1}
119 skip_fail: false
120
Dennis Dmitrievda9be462018-01-24 21:20:09 +0200121- description: Remove any existing minion keys
122 cmd: salt-key -y -D || true
123 node_name: {{ HOSTNAME_CFG01 }}
124 retry: {count: 1, delay: 1}
125 skip_fail: false
126
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300127- description: Configure salt-master on cfg01
128 cmd: |
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200129 cat << 'EOF' > /etc/salt/master.d/master.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300130 file_roots:
131 base:
132 - /usr/share/salt-formulas/env
133 pillar_opts: False
134 open_mode: True
135 reclass: &reclass
136 storage_type: yaml_fs
137 inventory_base_uri: /srv/salt/reclass
138 ext_pillar:
139 - reclass: *reclass
140 master_tops:
141 reclass: *reclass
142 EOF
143 node_name: {{ HOSTNAME_CFG01 }}
144 retry: {count: 1, delay: 1}
145 skip_fail: false
146
147- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300148 cmd: |
149 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200150 #touch /root/.git_trusted_certs.pem;
151 #for server in github.com; do \
152 # openssl s_client -showcerts -connect $server:443 </dev/null \
153 # | openssl x509 -outform PEM \
154 # >> /root/.git_trusted_certs.pem;
155 #done;
156 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
157 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
158 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300159 node_name: {{ HOSTNAME_CFG01 }}
160 retry: {count: 1, delay: 1}
161 skip_fail: false
162{%- endmacro %}
163
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200164
165{%- macro MACRO_CONFIG_DAY01_SALT_MASTER() %}
166{######################################}
167
168- description: Remove /etc/update-motd.d/52-info
169 cmd: rm -vf /etc/update-motd.d/52-info
170 node_name: {{ HOSTNAME_CFG01 }}
171 retry: {count: 1, delay: 10}
172 skip_fail: false
173
174- description: Set up static interface config
175 cmd: |
176 kill $(pidof /sbin/dhclient) || /bin/true
177 cat << 'EOF' > /etc/network/interfaces
178 # This file describes the network interfaces available on your system
179 # and how to activate them. For more information, see interfaces(5).
180
181 # The loopback network interface
182 auto lo
183 iface lo inet loopback
184
185 # The primary network interface
186 auto ens3
187 iface ens3 inet static
188 address {{ IPV4_NET_ADMIN_PREFIX }}.90
189 netmask 255.255.255.0
190 gateway {{ IPV4_NET_ADMIN_PREFIX }}.1
191 EOF
192 node_name: {{ HOSTNAME_CFG01 }}
193 retry: {count: 1, delay: 10}
194 skip_fail: false
195
196- description: Install common packages on cfg01
197 cmd: eatmydata apt-get update && apt-get install -y python-pip git curl at tmux byobu iputils-ping traceroute htop tree wget jq ntpdate
198 node_name: {{ HOSTNAME_CFG01 }}
199 retry: {count: 1, delay: 1}
200 skip_fail: false
201
202- description: Remove any existing minion keys
203 cmd: salt-key -y -D || true
204 node_name: {{ HOSTNAME_CFG01 }}
205 retry: {count: 1, delay: 1}
206 skip_fail: false
207
208- description: Configure GIT settings and certificates
209 cmd: |
210 set -e;
211 #touch /root/.git_trusted_certs.pem;
212 #for server in github.com; do \
213 # openssl s_client -showcerts -connect $server:443 </dev/null \
214 # | openssl x509 -outform PEM \
215 # >> /root/.git_trusted_certs.pem;
216 #done;
217 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
218 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
219 HOME=/root git config --global user.name "MCP Integration QA";
220 node_name: {{ HOSTNAME_CFG01 }}
221 retry: {count: 1, delay: 1}
222 skip_fail: false
223{%- endmacro %}
224
225
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300226{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false, WITH_MAAS=false) %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300227{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300228{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
229
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300230- description: Clone reclass models with submodules
231 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300232 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200233 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200234 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200235
236 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
237 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 +0200238 rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200239
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200240 pushd /srv/salt/reclass;
241 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
242 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200243 {%- if SALT_MODELS_REF_CHANGE != '' %}
244 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200245 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200246 {%- endfor %}
247 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200248 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200249 {%- endif %}
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300250
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300251 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300252 pushd classes/system/ && \
253 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200254 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300255 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200256 popd;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300257 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
258 pushd classes/system/;
259 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
260 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300261 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
262 pushd classes/system/;
263 git fetch --all --tags --prune
264 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
265 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200266 {%- endif %}
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300267
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200268 popd;
269 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300270 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200271
272 # Replace firstly to an intermediate value to avoid intersection between
273 # already replaced and replacing networks.
274 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
275 # 192.168.10 -> 10.16.0 (generated network for admin)
276 # 10.16.0 -> <external network>
277 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300278 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200279 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10/==IPV4_NET_ADMIN_PREFIX==/g' {} +
280 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10/==IPV4_NET_CONTROL_PREFIX==/g' {} +
281 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0/==IPV4_NET_TENANT_PREFIX==/g' {} +
282 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Tatyana Leontovich26756912018-06-06 20:11:05 +0300283 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.60\.0/==IPV4_NET_CONTROL_PREFIX==/g' {} +
284 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.70\.0/==IPV4_NET_ADMIN_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200285
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200286 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
287 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
288 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
289 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 +0200290
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300291 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
Victor Ryzhenkine784bbf2018-12-21 03:58:00 +0400292 find ${REPLACE_DIRS} -type f -exec sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200293
Tatyana Leontovicha4a96b22018-04-25 14:30:24 +0300294 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300295 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300296 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 +0300297 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 +0300298 {%- endif %}
299
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200300 # Override some context parameters
301 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
302 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
303 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
304
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200305 # Create the cfg01 inventory file or use existing
306 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
307 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300308 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400309 - cluster.{{ CLUSTER_NAME }}.infra.config
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300310 {%- if WITH_MAAS %}
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200311 - cluster.{{ CLUSTER_NAME }}.infra.maas
312 - cluster.{{ CLUSTER_NAME }}.infra.maas-machines
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300313 {%- endif %}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300314 parameters:
315 _param:
316 linux_system_codename: xenial
317 reclass_data_revision: master
318 linux:
319 system:
320 name: cfg01
321 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200322 reclass:
323 storage:
324 data_source:
325 engine: local
326 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300327
328 # Show the changes to the console
329 cd /srv/salt/reclass/; git diff
330 node_name: {{ HOSTNAME_CFG01 }}
331 retry: {count: 1, delay: 1}
332 skip_fail: false
333{%- endmacro %}
334
Dmitry Tyzhnenkofcb4dab2019-03-05 20:11:59 +0200335{%- macro MACRO_UPLOAD_AND_IMPORT_GPG_ENCRYPTION_KEY() %}
336{%- set KEY_FILE_NAME = 'encryption-key.asc' %}
337- description: "Upload gpg encruption key"
338 upload:
339 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
340 local_filename: {{ KEY_FILE_NAME }}
341 remote_path: /root/
342 node_name: {{ HOSTNAME_CFG01 }}
343
344- description: Import encryption key
345 cmd: |
346 set -e;
347 set -x;
348 gpg --import {{ KEY_FILE_NAME }}
349 gpg --list-keys
350 node_name: {{ HOSTNAME_CFG01 }}
351 retry: {count: 1, delay: 1}
352 skip_fail: false
353
354- description: Put encryption key to reclass folder
355 cmd: |
356 set -e;
357 set -x;
358 mkdir -p /srv/salt/reclass
359 cp /root/{{ KEY_FILE_NAME }} /srv/salt/reclass/
360 node_name: {{ HOSTNAME_CFG01 }}
361 retry: {count: 1, delay: 1}
362 skip_fail: false
363
364{%- endmacro %}
365
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300366
sgudz160b7302017-12-22 17:01:10 +0200367{%- 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 +0300368{###################################################################}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300369{%- set CLUSTER_CONTEXT_PATH = '/root/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200370- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300371 upload:
372 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
373 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300374 remote_path: /root/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300375 node_name: {{ HOSTNAME_CFG01 }}
376
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300377- description: "Show options enabled in the context file for model generation"
378 cmd: |
379 echo "===== Options enabled in the context for generation the model {{ LAB_CONFIG_NAME }} ====="
380 fgrep "True" {{ CLUSTER_CONTEXT_PATH }}
381 echo "===== Sources for model generation ====="
382 echo "# mcp_version: {{ REPOSITORY_SUITE }}"
383 echo "COOKIECUTTER_TEMPLATES_REPOSITORY={{ COOKIECUTTER_TEMPLATES_REPOSITORY }}"
384 {%- if CLUSTER_PRODUCT_MODELS != '' %}
385 echo "CLUSTER_PRODUCT_MODELS={{ CLUSTER_PRODUCT_MODELS }}"
386 {%- endif %}
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300387 {%- if COOKIECUTTER_REF_CHANGE != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300388 echo "COOKIECUTTER_REF_CHANGE={{ COOKIECUTTER_REF_CHANGE }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300389 {%- elif COOKIECUTTER_TEMPLATE_COMMIT != '' %}
390 echo "COOKIECUTTER_TEMPLATE_COMMIT={{ COOKIECUTTER_TEMPLATE_COMMIT }}"
Dennis Dmitriev713dce22018-07-03 11:47:46 +0300391 {%- elif COOKIECUTTER_TAG != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300392 echo "COOKIECUTTER_TAG={{ COOKIECUTTER_TAG }}"
393 {%- endif %}
394 echo "SALT_MODELS_SYSTEM_REPOSITORY={{ SALT_MODELS_SYSTEM_REPOSITORY }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300395 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300396 echo "SALT_MODELS_SYSTEM_REF_CHANGE={{ SALT_MODELS_SYSTEM_REF_CHANGE }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300397 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
398 echo "SALT_MODELS_SYSTEM_COMMIT={{ SALT_MODELS_SYSTEM_COMMIT }}"
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300399 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
400 echo "SALT_MODELS_SYSTEM_TAG={{ SALT_MODELS_SYSTEM_TAG }}"
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300401 {%- endif %}
402 echo "======================================="
403 node_name: {{ HOSTNAME_CFG01 }}
404 retry: {count: 1, delay: 1}
405 skip_fail: false
406
Dennis Dmitriev06979442018-10-24 18:53:49 +0300407- description: "Upload {{ COOKIECUTTER_TEMPLATES_REPOSITORY_USER }} key"
408 upload:
409 local_path: {{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | dirname }}/
410 local_filename: {{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
411 remote_path: /tmp/
412 node_name: {{ HOSTNAME_CFG01 }}
413
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300414- description: Create cluster model from cookiecutter templates
415 cmd: |
416 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300417 set -x;
Tatyana Leontovich1ef60952018-12-19 00:36:50 +0200418 sudo apt-get install virtualenv -y
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300419 sudo apt-get install python-setuptools -y
Dennis Dmitrievb4b74032018-12-18 21:53:23 +0200420
421 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
422 . /root/venv-reclass-tools/bin/activate;
423 pip install -U pip
424
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300425 pip install cookiecutter
Dennis Dmitriev06979442018-10-24 18:53:49 +0300426
427 chmod 0600 /tmp/{{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
428 eval $(ssh-agent)
429 ssh-add /tmp/{{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300430 export GIT_SSL_NO_VERIFY=true; git clone {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} /root/cookiecutter-templates
sgudz4d816eb2017-11-13 11:58:05 +0200431
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300432 {%- if COOKIECUTTER_REF_CHANGE != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300433 pushd /root/cookiecutter-templates
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300434 git fetch {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
sgudz4d816eb2017-11-13 11:58:05 +0200435 popd
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300436 {%- elif COOKIECUTTER_TEMPLATE_COMMIT != '' %}
437 pushd /root/cookiecutter-templates
438 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
439 popd
Dennis Dmitriev713dce22018-07-03 11:47:46 +0300440 {%- elif COOKIECUTTER_TAG != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300441 pushd /root/cookiecutter-templates
Tatyana Leontovich819a6c82018-06-04 12:05:16 +0300442 git fetch --all --tags --prune
443 git checkout tags/{{ COOKIECUTTER_TAG }}
444 popd
445 {%- endif %}
446
Dennis Dmitrievddcea2f2018-12-18 21:21:11 +0200447 if [ -f /root/cookiecutter-templates/requirements.txt ]; then
448 pip install -r /root/cookiecutter-templates/requirements.txt
449 fi
450
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300451 mkdir -p /srv/salt/reclass/classes/cluster/
452 mkdir -p /srv/salt/reclass/classes/system/
453 mkdir -p /srv/salt/reclass/classes/service/
454 mkdir -p /srv/salt/reclass/nodes/_generated
455
456 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200457 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
458 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200459 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300460 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200461 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300462 {%- endif %}
463 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200464 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300465 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300466
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300467 # Replace firstly to an intermediate value to avoid intersection between
468 # already replaced and replacing networks.
469 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
470 # 192.168.10 -> 10.16.0 (generated network for admin)
471 # 10.16.0 -> <external network>
472 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300473 export REPLACE_DIRS="{{ CLUSTER_CONTEXT_PATH }} /root/cookiecutter-templates"
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300474 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
475 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
476 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
477 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300478
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300479 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
480 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
481 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
482 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 +0300483
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300484 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /root/cookiecutter-templates/cluster_product/)' %}
Dmitry Tyzhnenkofcb4dab2019-03-05 20:11:59 +0200485 mkdir -p /tmp/output /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/
sgudz160b7302017-12-22 17:01:10 +0200486 for item in {{ items }}; do
Dmitry Tyzhnenkofcb4dab2019-03-05 20:11:59 +0200487 [ "$item" = "stacklight2" ] && continue;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300488 python /root/cookiecutter-templates/generate.py \
489 --template /root/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300490 --config-file {{ CLUSTER_CONTEXT_PATH }} \
Dmitry Tyzhnenkofcb4dab2019-03-05 20:11:59 +0200491 --output-dir /tmp/output/$item/;
492 mv -v /tmp/output/$item/{{ CLUSTER_NAME }}/$item /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300493 done
494
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300495 export GIT_SSL_NO_VERIFY=true; git clone {{ SALT_MODELS_SYSTEM_REPOSITORY }} /srv/salt/reclass/classes/system/
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300496
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200497 # Create the cfg01 inventory file or use existing
498 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
499 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300500 classes:
501 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200502 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300503 EOF
504
505 node_name: {{ HOSTNAME_CFG01 }}
506 retry: {count: 1, delay: 1}
507 skip_fail: false
508
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300509- description: Modify generated model and reclass-system if necessary
510 cmd: |
511 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300512 set -x;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300513 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300514 pushd /srv/salt/reclass/classes/system/ && \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300515 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300516 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300517 {%- endfor %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300518 popd;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300519 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
520 pushd /srv/salt/reclass/classes/system/
521 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
522 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300523 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
524 pushd /srv/salt/reclass/classes/system/
525 git fetch --all --tags --prune
526 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
527 popd;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300528 {%- endif %}
529
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300530 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200531 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300532 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
533 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
534 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
535 {%- endif %}
536
537 node_name: {{ HOSTNAME_CFG01 }}
538 retry: {count: 1, delay: 1}
539 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +0300540
541- description: Restart salt-api
542 cmd: |
543 set -e;
544 systemctl restart salt-api
545
546 node_name: {{ HOSTNAME_CFG01 }}
547 retry: {count: 1, delay: 1}
548 skip_fail: false
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300549{%- endmacro %}
550
551
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300552{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
553{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300554
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200555- description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300556 cmd: |
557 set -e;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300558 mkdir -p /root/environment/;
559 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 +0300560
Vladimir Khlyunevf337c902018-12-06 12:29:24 +0400561 {%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300562 pushd /root/environment/environment_template &&
sgudzcced67d2017-10-11 15:56:09 +0300563 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
564 git checkout FETCH_HEAD &&
565 popd
Vladimir Khlyunevf337c902018-12-06 12:29:24 +0400566 {%- elif ENVIRONMENT_TEMPLATE_COMMIT != '' %}
567 pushd /root/environment/environment_template
568 git checkout {{ ENVIRONMENT_TEMPLATE_COMMIT }}
569 popd
570 {%- endif %}
571
sgudzcced67d2017-10-11 15:56:09 +0300572 node_name: {{ HOSTNAME_CFG01 }}
573 skip_fail: false
sgudzcced67d2017-10-11 15:56:09 +0300574
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300575{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200576- description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300577 upload:
578 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
579 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300580 remote_path: /root/environment/
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300581 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300582{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300583
Dennis Dmitriev1ddf6472018-11-25 22:30:12 +0200584- description: "Replace template addresses to actual environment addresses"
585 cmd: |
586 set -ex;
587 # Replace firstly to an intermediate value to avoid intersection between
588 # already replaced and replacing networks.
589 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
590 # 192.168.10 -> 10.16.0 (generated network for admin)
591 # 10.16.0 -> <external network>
592 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
593 export REPLACE_DIRS="/root/environment/"
594 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
595 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
596 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
597 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
598
599 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
600 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
601 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
602 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {} +
603 node_name: {{ HOSTNAME_CFG01 }}
604 retry: {count: 1, delay: 5}
605 skip_fail: false
606
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300607- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
608 cmd: |
609 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300610 set -x;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300611 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200612 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
613 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300614 pip install git+https://github.com/dis-xcom/reclass-tools;
615 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
616 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
617 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
618
Dennis Dmitriev6368f082018-02-23 13:30:30 -0500619 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
620 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
621 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 +0300622 fi;
623
624 node_name: {{ HOSTNAME_CFG01 }}
625 retry: {count: 1, delay: 5}
626 skip_fail: false
627
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200628- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300629 cmd: |
630 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200631 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 +0300632
633 node_name: {{ HOSTNAME_CFG01 }}
634 retry: {count: 1, delay: 5}
635 skip_fail: false
636
637- description: "[EXPERIMENTAL] Create environment model for virtual environment"
638 cmd: |
639 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300640 set -x;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200641 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300642 reclass-tools render --template-dir /root/environment/environment_template/ \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300643 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300644 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /root/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300645 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
646 node_name: {{ HOSTNAME_CFG01 }}
647 retry: {count: 1, delay: 5}
648 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300649
650- description: Modify generated model and reclass-system
651 cmd: |
652 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
653 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
Victor Ryzhenkine784bbf2018-12-21 03:58:00 +0400654 find ${REPLACE_DIRS} -type f -exec sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {} +
sgudz8c888ec2017-10-02 15:29:23 +0300655 node_name: {{ HOSTNAME_CFG01 }}
656 retry: {count: 1, delay: 1}
657 skip_fail: false
658
sgudzb7953382019-02-18 17:59:30 +0200659{%- if UPDATE_REPO_CUSTOM_TAG != '' %}
660- description: "[EXPERIMENTAL] Change update repos tag acording to defined in job"
661 cmd: |
662 . /root/venv-reclass-tools/bin/activate;
663 reclass-tools add-key parameters._param.linux_system_repo_update_url 'http://mirror.mirantis.com/update/{{ UPDATE_REPO_CUSTOM_TAG }}/' /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/openstack/init.yml;
Tatyana Leontovicha5e04c12019-03-07 18:27:13 +0200664 reclass-tools add-key parameters._param.linux_system_repo_update_url 'http://mirror.mirantis.com/update/{{ UPDATE_REPO_CUSTOM_TAG }}/' /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/kubernetes/init.yml;
sgudzb7953382019-02-18 17:59:30 +0200665 # Replace ubuntu_updates repo tag independently, because it has another url structure
666 reclass-tools add-key parameters.linux.system.repo.ubuntu_updates.source 'deb [arch=amd64] http://mirror.mirantis.com/{{ UPDATE_REPO_CUSTOM_TAG }}/ubuntu/ ${_param:linux_system_codename}-updates main restricted universe' /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/apt_repos.yml;
667 node_name: {{ HOSTNAME_CFG01 }}
668 retry: {count: 1, delay: 5}
669 skip_fail: false
670{%- endif %}
671
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300672{%- endmacro %}
673
674
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300675{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
676{#######################################################}
677- description: Configure reclass
678 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300679 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300680 set -x;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300681 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300682 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200683 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200684 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
685 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300686 apt-get clean; apt-get update;
687 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
688 declare -a formula_services=({{ FORMULA_SERVICES }});
689 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200690 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300691 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300692 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
693 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
694 done;
695 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
696 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
697 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
698
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200699 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300700 storage_type: yaml_fs
701 pretty_print: True
702 output: yaml
703 inventory_base_uri: /srv/salt/reclass
704 EOF
705 node_name: {{ HOSTNAME_CFG01 }}
706 retry: {count: 1, delay: 1}
707 skip_fail: false
708
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200709- 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 +0300710 cmd: |
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200711 # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top'
712 find /srv/salt/reclass/nodes/ -type f -not -name cfg01.{{ DOMAIN_NAME }}.yml -delete
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300713 node_name: {{ HOSTNAME_CFG01 }}
714 retry: {count: 1, delay: 5}
715 skip_fail: false
716
717- description: Configure salt adoptors on cfg01
718 cmd: |
719 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
720 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
721 node_name: {{ HOSTNAME_CFG01 }}
722 retry: {count: 1, delay: 1}
723 skip_fail: false
724
725- description: Show reclass-salt --top for cfg01 node
726 cmd: reclass-salt --top
727 node_name: {{ HOSTNAME_CFG01 }}
728 retry: {count: 1, delay: 5}
729 skip_fail: false
730
731- description: Restart salt-master service
ibumarskov712a6872018-04-25 09:22:15 +0400732 cmd: service salt-master restart;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300733 node_name: {{ HOSTNAME_CFG01 }}
734 retry: {count: 1, delay: 5}
735 skip_fail: false
736{%- endmacro %}
737
738
739{%- macro MACRO_INSTALL_SALT_MINIONS() %}
740{#######################################}
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200741{%- for ssh in config.underlay.ssh %}
742 {%- set salt_roles = [] %}
743 {%- for role in ssh['roles'] %}
744 {%- if role in config.salt_deploy.salt_roles %}
745 {%- set _ = salt_roles.append(role) %}
746 {%- endif %}
747 {%- endfor %}
748
749 {%- if salt_roles %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300750- description: Configure salt-minion on {{ ssh['node_name'] }}
751 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300752 set -ex;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300753 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitriev3fe24dd2018-07-20 18:38:57 +0300754 cat << EOF > /etc/salt/minion.d/minion.conf
755 id: $(hostname -s).{{ DOMAIN_NAME }}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300756 master: {{ config.salt.salt_master_host }}
757 EOF
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200758
759 # Configure ubuntu and salt repositories
760 which wget >/dev/null || (apt-get update; apt-get install -y wget);
761
762 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
763 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
764 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
765 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
766
767 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300768 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
769
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200770
771 apt-get clean
772 apt-get update
773
774 # Install salt-minion
Tatyana Leontovich47708552018-12-19 16:36:09 +0200775 apt-get install eatmydata -y;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300776 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200777 # Install common packages
778 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200779 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200780 # Restart salt-minion if it was already installed
781 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300782 node_name: {{ ssh['node_name'] }}
783 retry: {count: 1, delay: 1}
784 skip_fail: false
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200785 {%- else %}
786- description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }}
787 cmd: echo "SSH to $(hostname -f) passed"
788 node_name: {{ ssh['node_name'] }}
789 retry: {count: 1, delay: 1}
790 skip_fail: false
791 {%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300792
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200793{%- endfor %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300794
795- description: Accept salt keys from all the nodes
796 cmd: salt-key -A -y
797 node_name: {{ HOSTNAME_CFG01 }}
798 retry: {count: 1, delay: 5}
799 skip_fail: true
800{%- endmacro %}
801
802
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200803{%- macro MACRO_INSTALL_FORMULAS(FORMULA_SERVICES='') %}
804{#######################################################}
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300805- description: Install salt formulas
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200806 cmd: |
807 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300808 set -x;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200809 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
810 which wget > /dev/null || (apt-get update; apt-get install -y wget);
811 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
812 # echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
813 # wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
814 apt-get clean; apt-get update;
815 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
816 declare -a formula_services=({{ FORMULA_SERVICES }});
817 echo -e "\nInstalling all required salt formulas\n";
818 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300819 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200820 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
821 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
822 done;
823 node_name: {{ HOSTNAME_CFG01 }}
824 retry: {count: 1, delay: 1}
825 skip_fail: false
Dennis Dmitriev010f0292018-07-28 23:33:48 +0300826
827- description: Sync all salt resources on salt-master minion
828 cmd: salt-call saltutil.sync_all && sleep 5
829 node_name: {{ HOSTNAME_CFG01 }}
830 retry: {count: 1, delay: 5}
831 skip_fail: false
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200832{%- endmacro %}
833
834{%- macro MACRO_CONFIG_DAY01_SALT_MINION() %}
835{#######################################}
836- description: Configure salt-minion on {{ HOSTNAME_CFG01 }}
837 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300838 set -ex;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200839 export SALT_MASTER_MINION_ID={{ HOSTNAME_CFG01 }}
840 envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
841 service salt-minion restart
842
843 while true; do
844 salt-key | grep "$SALT_MASTER_MINION_ID" && break
845 sleep 5
846 done
847
848 sleep 5
849
850 for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do
851 salt-key -d $i -y
852 done
853 node_name: {{ HOSTNAME_CFG01 }}
854 retry: {count: 1, delay: 1}
855 skip_fail: false
856{%- endmacro %}
857
858
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300859{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
860{##################################################}
861
862{# Prepare salt services and nodes settings #}
863
sgudz6e797562018-10-22 12:27:09 +0300864- description: '*Workaround* of harcoded host from day01 grains'
865 cmd: salt-key -d cfg01.mcp-day01.local -y
866 node_name: {{ HOSTNAME_CFG01 }}
867 retry: {count: 1, delay: 1}
868 skip_fail: true
869
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300870- description: Run 'linux' formula on cfg01
871 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
872 node_name: {{ HOSTNAME_CFG01 }}
873 retry: {count: 3, delay: 5}
874 skip_fail: false
875
876- description: Run 'openssh' formula on cfg01
877 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300878 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300879 salt --hard-crash --state-output=mixed --state-verbose=False
880 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +0300881 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300882 node_name: {{ HOSTNAME_CFG01 }}
883 retry: {count: 3, delay: 5}
884 skip_fail: false
885
886- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
887 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
888 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
889 node_name: {{ HOSTNAME_CFG01 }}
890 retry: {count: 1, delay: 1}
891 skip_fail: false
892
893- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300894 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 +0300895 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300896 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300897 skip_fail: false
898
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400899{%- if SALT_FORMULAS_REFS != '' %}
900- description: Replace needed formulas to desired version
901 cmd: |
902 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300903 set -x;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400904 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
905 {% set formula = formula_set.split(':') %}
906 {% set formula_name = formula[0] %}
907 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300908 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400909 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
910 pushd {{ formula_dir }} &&
911 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
912 git checkout FETCH_HEAD &&
913 popd &&
914 if [ -d "{{ formula_dir }}" ]; then
915 echo "Going to replace packaged formula {{ formula_name }}" &&
916 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400917 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
918 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400919 else
920 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
921 fi
922 {%- endfor %}
923 node_name: {{ HOSTNAME_CFG01 }}
924 retry: {count: 1, delay: 10}
925 skip_fail: false
926{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300927
928- description: Refresh pillars on salt-master minion
929 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
930 node_name: {{ HOSTNAME_CFG01 }}
931 retry: {count: 1, delay: 5}
932 skip_fail: false
933
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300934- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300935 cmd: reclass-salt --top
936 node_name: {{ HOSTNAME_CFG01 }}
937 retry: {count: 1, delay: 5}
938 skip_fail: false
939
940- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300941 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 +0300942 node_name: {{ HOSTNAME_CFG01 }}
943 retry: {count: 1, delay: 5}
944 skip_fail: false
945
946- description: Configure linux on master
947 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
948 node_name: {{ HOSTNAME_CFG01 }}
949 retry: {count: 1, delay: 5}
950 skip_fail: false
951
952- description: Configure salt.minion on master
953 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
954 -C 'I@salt:master' state.sls salt.minion && sleep 10
955 node_name: {{ HOSTNAME_CFG01 }}
956 retry: {count: 3, delay: 10}
957 skip_fail: false
958
959- description: Run state 'salt' on master (for salt.api, etc)
960 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
961 -C 'I@salt:master' state.sls salt
962 node_name: {{ HOSTNAME_CFG01 }}
963 retry: {count: 3, delay: 10}
964 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +0300965
966- description: Restart salt-api after states
967 cmd: systemctl restart salt-api
968 node_name: {{ HOSTNAME_CFG01 }}
969 retry: {count: 3, delay: 10}
970 skip_fail: false
971
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300972{%- endmacro %}
973
Dennis Dmitriev85559962018-01-30 15:35:51 +0200974{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
975{#################################################################}
976
977- description: Refresh pillars before generating nodes
978 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
979 node_name: {{ HOSTNAME_CFG01 }}
980 retry: {count: 1, delay: 5}
981 skip_fail: false
982
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +0200983- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200984 cmd: |
985 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300986 set -x;
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200987 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
988 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 +0200989 node_name: {{ HOSTNAME_CFG01 }}
990 retry: {count: 1, delay: 5}
991 skip_fail: false
992
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300993- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
994 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
995 -C 'I@salt:master' state.sls reclass
996 node_name: {{ HOSTNAME_CFG01 }}
997 retry: {count: 1, delay: 5}
998 skip_fail: false
999
Dennis Dmitriev85559962018-01-30 15:35:51 +02001000{%- if RERUN_SALTMASTER_STATE %}
1001- description: Regenerate salt.master states for the newly uploaded/created model
1002 cmd: |
1003 # Need to refresh installed formulas that are required in the model
1004 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
1005 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
1006 node_name: {{ HOSTNAME_CFG01 }}
1007 retry: {count: 1, delay: 5}
1008 skip_fail: false
1009{%- endif %}
1010
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001011- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +02001012 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001013 node_name: {{ HOSTNAME_CFG01 }}
1014 retry: {count: 1, delay: 5}
1015 skip_fail: false
1016
Dennis Dmitriev3e731a42017-08-30 17:12:59 +03001017- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +03001018 cmd: |
1019 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +03001020 set -x;
Dennis Dmitriev4386a072017-09-04 13:58:02 +03001021 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
1022 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
1023 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001024 node_name: {{ HOSTNAME_CFG01 }}
1025 retry: {count: 1, delay: 5}
1026 skip_fail: false
1027
1028- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +03001029 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001030 node_name: {{ HOSTNAME_CFG01 }}
1031 retry: {count: 1, delay: 5}
1032 skip_fail: false
1033{%- endmacro %}
1034
1035
1036{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
1037{########################################}
1038# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +02001039
1040- description: Get linux kernel version from all minions
1041 cmd: |
1042 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
1043 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
1044 node_name: {{ HOSTNAME_CFG01 }}
1045 retry: {count: 5, delay: 10}
1046 skip_fail: false
1047
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001048- description: Configure linux on other nodes
1049 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
1050 node_name: {{ HOSTNAME_CFG01 }}
1051 retry: {count: 5, delay: 10}
1052 skip_fail: false
1053
1054- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +03001055 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 +03001056 salt --hard-crash --state-output=mixed --state-verbose=False
1057 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +03001058 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001059 node_name: {{ HOSTNAME_CFG01 }}
1060 retry: {count: 1, delay: 5}
1061 skip_fail: false
1062
1063- description: Configure salt.minion on other nodes
1064 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 +04001065 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001066 node_name: {{ HOSTNAME_CFG01 }}
1067 retry: {count: 3, delay: 15}
1068 skip_fail: false
1069
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001070- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +04001071 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001072 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +04001073 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001074 skip_fail: false
1075
Victor Ryzhenkina06443e2018-03-15 17:25:19 +04001076- description: Update minion information
Dennis Dmitrievea291ee2018-03-16 12:27:43 +02001077 cmd: |
1078 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001079 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 60
Victor Ryzhenkina06443e2018-03-15 17:25:19 +04001080 node_name: {{ HOSTNAME_CFG01 }}
1081 retry: {count: 1, delay: 10}
1082 skip_fail: false
1083
Dennis Dmitriev14183db2018-03-01 15:14:12 +02001084- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
1085 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
1086 node_name: {{ HOSTNAME_CFG01 }}
1087 retry: {count: 1, delay: 10}
1088 skip_fail: false
1089
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001090- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001091 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001092 node_name: {{ HOSTNAME_CFG01 }}
1093 retry: {count: 3, delay: 15}
1094 skip_fail: false
1095
1096- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001097 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001098 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001099 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001100 skip_fail: false
1101
1102- description: Configure ntp and rsyslog on nodes
1103 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
1104 node_name: {{ HOSTNAME_CFG01 }}
1105 retry: {count: 1, delay: 10}
1106 skip_fail: false
Tatyana Leontovich529e4052018-07-09 18:30:48 +03001107
1108- description: Install and configure iptables if it is in pillar
1109 cmd: |
1110 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' match.pillar 'iptables:service' ; then
1111 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' state.sls iptables
1112 fi
1113 node_name: {{ HOSTNAME_CFG01 }}
1114 retry: {count: 1, delay: 10}
1115 skip_fail: false
1116
1117
1118- description: Install and configure logrotate if it is in pillar
1119 cmd: |
1120 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' match.pillar 'logrotate:server' ; then
1121 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' state.sls logrotate
1122 fi
1123 node_name: {{ HOSTNAME_CFG01 }}
1124 retry: {count: 1, delay: 10}
1125 skip_fail: false
1126
1127- description: Install and configure auditd if it is enabled
1128 cmd: |
1129 if salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" match.pillar 'auditd:service'; then
1130 salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" state.sls auditd
1131 fi
1132 node_name: {{ HOSTNAME_CFG01 }}
1133 retry: {count: 1, delay: 10}
1134 skip_fail: false
1135
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02001136{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001137
1138
1139{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
1140{#########################################}
1141
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001142- description: '*Workaround: Load bonding module before call state.linux'
1143 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
1144 node_name: {{ HOSTNAME_CFG01 }}
1145 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +03001146 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001147
1148- description: '*Workaround* install bridge-utils before running linux formula'
1149 # The formula removes default route and then tries to install the package, fails.
1150 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
1151 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
1152 node_name: {{ HOSTNAME_CFG01 }}
1153 retry: {count: 1, delay: 5}
1154 skip_fail: false
1155
1156{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001157
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001158
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001159{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001160{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001161
1162- description: Set k8s deploy parameters
1163 cmd: |
1164 {% for k8s_opt, value in config.k8s_deploy.items() %}
1165 {% if value|string() %}
1166 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
1167 {% endif %}
1168 {% endfor %}
1169 node_name: {{ HOSTNAME_CFG01 }}
1170 retry: {count: 1, delay: 1}
1171 skip_fail: false
1172
1173{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001174
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001175
1176{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
1177{#############################################}
1178- description: Set SL docker images deploy parameters
1179 cmd: |
1180 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
1181 {%- for sl_opt, value in config.sl_deploy.items() %}
1182 {%- if value|string() %}
1183 {%- if OVERRIDES_FILENAME %}
1184 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
1185 {%- else %}
1186 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
1187 {%- endif %}
1188 {%- endif %}
1189 {%- endfor %}
1190 salt '*' saltutil.refresh_pillar;
1191 sleep 10
1192 node_name: {{ HOSTNAME_CFG01 }}
1193 retry: {count: 1, delay: 1}
1194 skip_fail: false
1195{%- endmacro %}
1196
1197
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001198{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001199{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001200
1201{% for ssh in config.underlay.ssh %}
1202{% if ssh["node_name"].startswith("cmp") %}
1203{% set node_hostname = ssh["node_name"].split('.')[0] %}
1204- description: Register compute {{ ssh['node_name'] }}
1205 cmd: |
1206 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
1207 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
1208 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +04001209 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001210 export config_host={{ config.salt.salt_master_host }}
1211 export node_domain={{ DOMAIN_NAME }}
1212 export nodes_os="xenial"
1213 export node_hostname={{ node_hostname }}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001214 export saltversion={{ SALT_VERSION }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001215 set -xe
1216 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
1217 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
1218 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
1219 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
1220
1221 # Add wrapper to apt-get to avoid race conditions
1222 # with cron jobs running 'unattended-upgrades' script
1223 aptget_wrapper() {
1224 local apt_wrapper_timeout=300
1225 local start_time=$(date '+%s')
1226 local fin_time=$((start_time + apt_wrapper_timeout))
1227 while true; do
1228 if (( "$(date '+%s')" > fin_time )); then
1229 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
1230 fi
1231 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
1232 echo "Waiting while another apt/dpkg process releases locks ..."
1233 sleep 30
1234 continue
1235 else
1236 apt-get $@
1237 break
1238 fi
1239 done
1240 }
1241
1242 # Set default salt version
1243 if [ -z "$saltversion" ]; then
Tatyana Leontovich14e201d2018-07-05 13:28:54 +03001244 saltversion="2017.7"
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001245 fi
1246 echo "Using Salt version $saltversion"
1247
1248 echo "Preparing base OS ..."
1249
1250 case "$node_os" in
1251 trusty)
1252 # workaround for old cloud-init only configuring the first iface
1253 iface_config_dir="/etc/network/interfaces"
1254 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
1255
1256 for iface in $ifaces; do
1257 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
1258 done
1259
1260 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1261
1262 # SUGGESTED UPDATE:
1263 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1264 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1265 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1266 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1267 #install_salt_minion_pkg
1268
1269 # DEPRECATED:
1270 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1271 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1272
1273 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
1274 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1275
1276 aptget_wrapper clean
1277 aptget_wrapper update
1278 aptget_wrapper install -y salt-common
1279 aptget_wrapper install -y salt-minion
1280 ;;
1281 xenial)
1282
1283 # workaround for new cloud-init setting all interfaces statically
1284 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
1285
1286 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1287
1288 # SUGGESTED UPDATE:
1289 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1290 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1291 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1292 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1293 #install_salt_minion_pkg
1294
1295 # DEPRECATED:
1296 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1297 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1298
1299 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
1300 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1301
1302 aptget_wrapper clean
1303 aptget_wrapper update
1304 aptget_wrapper install -y salt-minion
1305 ;;
1306 rhel|centos|centos7|centos7|rhel6|rhel7)
1307 yum install -y git
1308 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1309 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1310 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1311 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1312 install_salt_minion_pkg
1313 ;;
1314 *)
1315 msg="OS '$node_os' is not supported."
1316 esac
1317
1318 echo "Configuring Salt minion ..."
1319 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
1320 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
1321
1322 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
1323
1324 sleep 1
1325
1326 echo "Classifying node ..."
1327 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
1328 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1329 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1330 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1331 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1332 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1333
1334 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1335 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1336 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1337 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1338 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1339
1340 if [ "$node_network05_iface" != "" ]; then
1341 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
1342 fi
1343
1344 # find more parameters (every env starting param_)
1345 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
1346 if [ "$more_params" != "" ]; then
1347 echo "Additional params: $more_params"
1348 more_params=", $more_params"
1349 fi
1350
1351 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}}"
1352
1353 sleep 5
1354
1355 salt-call saltutil.sync_all
1356 salt-call mine.flush
1357 salt-call mine.update
1358 node_name: {{ ssh['node_name'] }}
1359 retry: {count: 1, delay: 1}
1360 skip_fail: false
1361{%- endif %}
1362{%- endfor %}
1363
1364- description: Refresh pillars on all minions
1365 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1366 node_name: {{ HOSTNAME_CFG01 }}
1367 retry: {count: 1, delay: 5}
1368 skip_fail: false
1369
1370- description: Sync all salt resources
1371 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1372 node_name: {{ HOSTNAME_CFG01 }}
1373 retry: {count: 1, delay: 5}
1374 skip_fail: false
1375
sgudz160b7302017-12-22 17:01:10 +02001376{%- endmacro %}
sgudz09e9aa92018-04-12 12:31:53 +03001377
1378{%- macro RUN_NEW_TEMPEST() %}
1379{###################################}
1380
1381- description: Upload tempest template
1382 upload:
1383 local_path: {{ config.salt_deploy.templates_dir }}
1384 local_filename: runtest.yml
1385 remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/
1386 node_name: {{ HOSTNAME_CFG01 }}
1387 skip_fail: False
1388
1389- description: Include class with tempest template into cfg node
1390 cmd: |
1391 sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml;
1392 salt 'cfg01*' saltutil.refresh_pillar;
1393 salt 'cfg01*' saltutil.sync_all;
1394 node_name: {{ HOSTNAME_CFG01 }}
1395 retry: {count: 1, delay: 10}
1396 skip_fail: false
1397
Oleksii Butenko2e8e8ee2018-06-21 11:10:13 +03001398- description: Execute salt.minion on config node
1399 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False state.sls salt.minion;
1400 node_name: {{ HOSTNAME_CFG01 }}
1401 retry: {count: 1, delay: 5}
1402 skip_fail: false
1403
1404- description: Test ping
1405 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False test.ping;
1406 node_name: {{ HOSTNAME_CFG01 }}
1407 retry: {count: 1, delay: 5}
1408 skip_fail: false
1409
sgudz09e9aa92018-04-12 12:31:53 +03001410- description: Create flavors for tests
1411 cmd: |
1412 salt 'cfg01*' state.sls nova.client;
1413 node_name: {{ HOSTNAME_CFG01 }}
1414 retry: {count: 1, delay: 5}
1415 skip_fail: false
1416
1417- description: Create networks for tests
1418 cmd: |
1419 salt 'cfg01*' state.sls neutron.client;
1420 node_name: {{ HOSTNAME_CFG01 }}
1421 retry: {count: 1, delay: 5}
1422 skip_fail: false
1423
1424- description: Upload cirros image
1425 cmd: |
1426 salt 'cfg01*' state.sls glance.client;
1427 node_name: {{ HOSTNAME_CFG01 }}
1428 retry: {count: 1, delay: 5}
1429 skip_fail: false
1430
1431- description: Generate tempest config
1432 cmd: |
1433 salt 'cfg01*' state.sls runtest;
1434 node_name: {{ HOSTNAME_CFG01 }}
1435 retry: {count: 1, delay: 5}
1436 skip_fail: false
1437
1438- description: Run tempest from new docker image
1439 cmd: |
Oleksii Butenko71d76f32018-06-05 17:46:34 +03001440 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 +03001441 node_name: {{ HOSTNAME_GTW01 }}
1442 retry: {count: 1, delay: 30}
1443 skip_fail: true
1444
1445- description: Download xml results
1446 download:
1447 remote_path: /root/test/
1448 remote_filename: "report_*.xml"
1449 local_path: {{ os_env('PWD') }}
1450 node_name: {{ HOSTNAME_GTW01 }}
1451 skip_fail: true
1452
1453{%- endmacro %}
Oleksii Butenko5cd0a162018-06-14 18:18:10 +03001454
1455{%- macro INSTALL_DOCKER_ON_GTW() %}
1456{###################################}
1457
1458- description: Install docker.io on gtw
1459 cmd: salt-call cmd.run 'apt-get install docker.io -y'
1460 node_name: {{ HOSTNAME_GTW01 }}
1461 retry: {count: 1, delay: 30}
1462 skip_fail: false
1463
1464- description: Enable forward policy
1465 cmd: iptables --policy FORWARD ACCEPT
1466 node_name: {{ HOSTNAME_GTW01 }}
1467 retry: {count: 1, delay: 30}
1468 skip_fail: false
1469
1470{%- endmacro %}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001471
1472{%- macro MACRO_CHECK_SALT_VERSION_ON_NODES() %}
1473{#####################################################}
1474
1475{%- for ssh in config.underlay.ssh %}
1476 {%- set salt_roles = [] %}
1477 {%- for role in ssh['roles'] %}
1478 {%- if role in config.salt_deploy.salt_roles %}
1479 {%- set _ = salt_roles.append(role) %}
1480 {%- endif %}
1481 {%- endfor %}
1482
1483 {%- if salt_roles %}
1484- description: 'Check salt version is as expected'
1485 cmd: salt-call test.version | grep {{ SALT_VERSION }}
1486 node_name: {{ ssh['node_name'] }}
1487 retry: {count: 1, delay: 1}
1488 skip_fail: false
1489 {%- endif %}
1490
1491{%- endfor %}
1492{%- endmacro %}
1493
1494{%- macro MACRO_CHECK_SALT_VERSION_SERVICES_ON_CFG() %}
1495{#####################################################}
1496
1497- description: 'Check salt-api, salt-master and salt-minion version'
1498 cmd: |
1499 salt-master --version | grep {{ SALT_VERSION }};
1500 salt-minion --version | grep {{ SALT_VERSION }};
1501 salt-api --version | grep {{ SALT_VERSION }};
1502 node_name: {{ HOSTNAME_CFG01 }}
1503 retry: {count: 1, delay: 5}
1504 skip_fail: false
1505
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001506{%- endmacro %}