blob: c3bc0f321e4ff406e0d89a00dcf16982d1d58ef1 [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') %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +030037
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020038{# Address pools for reclass cluster model are taken in the following order:
39 # 1. environment variables,
40 # 2. config.underlay.address_pools based on fuel-devops address pools
41 # (see generated '.ini' file after underlay is created),
42 # 3. defaults #}
43{% set address_pools = config.underlay.address_pools %}
44{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
45{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
46{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
47{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
48{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
49{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
50{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
51{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
52
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040053{# Format for formula replacement:
54 # space separated string:
55 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
56
57{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
Tatyana Leontovich1c101312018-04-18 20:33:08 +030058{% set TEMPEST_PATTERN = os_env('TEMPEST_PATTERN', 'tempest') %}
Tatyana Leontovich69700712018-04-23 12:26:57 +030059{% set EXCLUDE_TEST_ARGS = os_env('EXCLUDE_TEST_ARGS', '') %}
Dennis Dmitriev0f272312018-10-01 13:29:40 +030060{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.com/salt-formulas') %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040061
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040062# Needed for using different models in different templates
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020063{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040064
Dennis Dmitriev492813e2017-08-09 15:08:58 +030065
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020066{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
67{#####################################################}
68
69- description: 'Configure key on nodes and install packages'
70 cmd: |
71 rm -rf trusted* ;
72 rm -rf /etc/apt/sources.list ;
Dennis Dmitrievcf777802018-02-14 18:09:55 +020073 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020074 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
75 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
76 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +030077 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020078 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
79 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
80 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
Dennis Dmitrievf4e6efc2018-03-26 06:15:10 -050081 eatmydata apt-get clean;
82 apt-get update;
Dennis Dmitriev01d5e372018-03-15 23:29:29 +020083 sync;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020084 node_name: {{ NODE_NAME }}
85 retry: {count: 1, delay: 5}
86 skip_fail: false
87
88{%- endmacro %}
89
90
Dennis Dmitriev492813e2017-08-09 15:08:58 +030091{%- macro MACRO_INSTALL_SALT_MASTER() %}
92{######################################}
93- description: Installing salt master on cfg01
Dennis Dmitrievcf777802018-02-14 18:09:55 +020094 cmd: |
95 which wget >/dev/null || (apt-get update; apt-get install -y wget);
96 # Configure ubuntu and salt repositories
97 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
98 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
99 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
100 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
101
102 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
103 wget -O - {{ FORMULA_GPG }} | apt-key add -;
104 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300105 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
106
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200107
108 apt-get clean
109 apt-get update
110
111 # Install salt-master and reclass
112 eatmydata apt-get install -y --allow-unauthenticated reclass salt-master
113 # Install common packages
Dennis Dmitrievf88fc7d2018-02-20 15:40:08 +0200114 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 +0200115 sync;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300116 node_name: {{ HOSTNAME_CFG01 }}
117 retry: {count: 1, delay: 1}
118 skip_fail: false
119
Dennis Dmitrievda9be462018-01-24 21:20:09 +0200120- description: Remove any existing minion keys
121 cmd: salt-key -y -D || true
122 node_name: {{ HOSTNAME_CFG01 }}
123 retry: {count: 1, delay: 1}
124 skip_fail: false
125
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300126- description: Configure salt-master on cfg01
127 cmd: |
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200128 cat << 'EOF' > /etc/salt/master.d/master.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300129 file_roots:
130 base:
131 - /usr/share/salt-formulas/env
132 pillar_opts: False
133 open_mode: True
134 reclass: &reclass
135 storage_type: yaml_fs
136 inventory_base_uri: /srv/salt/reclass
137 ext_pillar:
138 - reclass: *reclass
139 master_tops:
140 reclass: *reclass
141 EOF
142 node_name: {{ HOSTNAME_CFG01 }}
143 retry: {count: 1, delay: 1}
144 skip_fail: false
145
146- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300147 cmd: |
148 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200149 #touch /root/.git_trusted_certs.pem;
150 #for server in github.com; do \
151 # openssl s_client -showcerts -connect $server:443 </dev/null \
152 # | openssl x509 -outform PEM \
153 # >> /root/.git_trusted_certs.pem;
154 #done;
155 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
156 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
157 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300158 node_name: {{ HOSTNAME_CFG01 }}
159 retry: {count: 1, delay: 1}
160 skip_fail: false
161{%- endmacro %}
162
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200163
164{%- macro MACRO_CONFIG_DAY01_SALT_MASTER() %}
165{######################################}
166
167- description: Remove /etc/update-motd.d/52-info
168 cmd: rm -vf /etc/update-motd.d/52-info
169 node_name: {{ HOSTNAME_CFG01 }}
170 retry: {count: 1, delay: 10}
171 skip_fail: false
172
173- description: Set up static interface config
174 cmd: |
175 kill $(pidof /sbin/dhclient) || /bin/true
176 cat << 'EOF' > /etc/network/interfaces
177 # This file describes the network interfaces available on your system
178 # and how to activate them. For more information, see interfaces(5).
179
180 # The loopback network interface
181 auto lo
182 iface lo inet loopback
183
184 # The primary network interface
185 auto ens3
186 iface ens3 inet static
187 address {{ IPV4_NET_ADMIN_PREFIX }}.90
188 netmask 255.255.255.0
189 gateway {{ IPV4_NET_ADMIN_PREFIX }}.1
190 EOF
191 node_name: {{ HOSTNAME_CFG01 }}
192 retry: {count: 1, delay: 10}
193 skip_fail: false
194
195- description: Install common packages on cfg01
196 cmd: eatmydata apt-get update && apt-get install -y python-pip git curl at tmux byobu iputils-ping traceroute htop tree wget jq ntpdate
197 node_name: {{ HOSTNAME_CFG01 }}
198 retry: {count: 1, delay: 1}
199 skip_fail: false
200
201- description: Remove any existing minion keys
202 cmd: salt-key -y -D || true
203 node_name: {{ HOSTNAME_CFG01 }}
204 retry: {count: 1, delay: 1}
205 skip_fail: false
206
207- description: Configure GIT settings and certificates
208 cmd: |
209 set -e;
210 #touch /root/.git_trusted_certs.pem;
211 #for server in github.com; do \
212 # openssl s_client -showcerts -connect $server:443 </dev/null \
213 # | openssl x509 -outform PEM \
214 # >> /root/.git_trusted_certs.pem;
215 #done;
216 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
217 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
218 HOME=/root git config --global user.name "MCP Integration QA";
219 node_name: {{ HOSTNAME_CFG01 }}
220 retry: {count: 1, delay: 1}
221 skip_fail: false
222{%- endmacro %}
223
224
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300225{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false, WITH_MAAS=false) %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300226{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300227{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
228
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300229- description: Clone reclass models with submodules
230 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300231 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200232 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200233 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200234
235 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
236 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 +0200237 rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200238
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200239 pushd /srv/salt/reclass;
240 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
241 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200242 {%- if SALT_MODELS_REF_CHANGE != '' %}
243 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200244 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200245 {%- endfor %}
246 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200247 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200248 {%- endif %}
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300249
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300250 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300251 pushd classes/system/ && \
252 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200253 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300254 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200255 popd;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300256 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
257 pushd classes/system/;
258 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
259 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300260 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
261 pushd classes/system/;
262 git fetch --all --tags --prune
263 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
264 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200265 {%- endif %}
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300266
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200267 popd;
268 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300269 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200270
271 # Replace firstly to an intermediate value to avoid intersection between
272 # already replaced and replacing networks.
273 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
274 # 192.168.10 -> 10.16.0 (generated network for admin)
275 # 10.16.0 -> <external network>
276 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300277 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200278 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10/==IPV4_NET_ADMIN_PREFIX==/g' {} +
279 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10/==IPV4_NET_CONTROL_PREFIX==/g' {} +
280 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0/==IPV4_NET_TENANT_PREFIX==/g' {} +
281 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Tatyana Leontovich26756912018-06-06 20:11:05 +0300282 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.60\.0/==IPV4_NET_CONTROL_PREFIX==/g' {} +
283 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.70\.0/==IPV4_NET_ADMIN_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200284
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200285 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
286 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
287 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
288 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 +0200289
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300290 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 +0400291 find ${REPLACE_DIRS} -type f -exec sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200292
Tatyana Leontovicha4a96b22018-04-25 14:30:24 +0300293 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300294 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300295 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 +0300296 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 +0300297 {%- endif %}
298
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200299 # Override some context parameters
300 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
301 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
302 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
303
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200304 # Create the cfg01 inventory file or use existing
305 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
306 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300307 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400308 - cluster.{{ CLUSTER_NAME }}.infra.config
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300309 {%- if WITH_MAAS %}
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200310 - cluster.{{ CLUSTER_NAME }}.infra.maas
311 - cluster.{{ CLUSTER_NAME }}.infra.maas-machines
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300312 {%- endif %}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300313 parameters:
314 _param:
315 linux_system_codename: xenial
316 reclass_data_revision: master
317 linux:
318 system:
319 name: cfg01
320 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200321 reclass:
322 storage:
323 data_source:
324 engine: local
325 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300326
327 # Show the changes to the console
328 cd /srv/salt/reclass/; git diff
329 node_name: {{ HOSTNAME_CFG01 }}
330 retry: {count: 1, delay: 1}
331 skip_fail: false
332{%- endmacro %}
333
334
sgudz160b7302017-12-22 17:01:10 +0200335{%- 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 +0300336{###################################################################}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300337{%- set CLUSTER_CONTEXT_PATH = '/root/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200338- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300339 upload:
340 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
341 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300342 remote_path: /root/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300343 node_name: {{ HOSTNAME_CFG01 }}
344
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300345- description: "Show options enabled in the context file for model generation"
346 cmd: |
347 echo "===== Options enabled in the context for generation the model {{ LAB_CONFIG_NAME }} ====="
348 fgrep "True" {{ CLUSTER_CONTEXT_PATH }}
349 echo "===== Sources for model generation ====="
350 echo "# mcp_version: {{ REPOSITORY_SUITE }}"
351 echo "COOKIECUTTER_TEMPLATES_REPOSITORY={{ COOKIECUTTER_TEMPLATES_REPOSITORY }}"
352 {%- if CLUSTER_PRODUCT_MODELS != '' %}
353 echo "CLUSTER_PRODUCT_MODELS={{ CLUSTER_PRODUCT_MODELS }}"
354 {%- endif %}
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300355 {%- if COOKIECUTTER_REF_CHANGE != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300356 echo "COOKIECUTTER_REF_CHANGE={{ COOKIECUTTER_REF_CHANGE }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300357 {%- elif COOKIECUTTER_TEMPLATE_COMMIT != '' %}
358 echo "COOKIECUTTER_TEMPLATE_COMMIT={{ COOKIECUTTER_TEMPLATE_COMMIT }}"
Dennis Dmitriev713dce22018-07-03 11:47:46 +0300359 {%- elif COOKIECUTTER_TAG != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300360 echo "COOKIECUTTER_TAG={{ COOKIECUTTER_TAG }}"
361 {%- endif %}
362 echo "SALT_MODELS_SYSTEM_REPOSITORY={{ SALT_MODELS_SYSTEM_REPOSITORY }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300363 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300364 echo "SALT_MODELS_SYSTEM_REF_CHANGE={{ SALT_MODELS_SYSTEM_REF_CHANGE }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300365 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
366 echo "SALT_MODELS_SYSTEM_COMMIT={{ SALT_MODELS_SYSTEM_COMMIT }}"
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300367 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
368 echo "SALT_MODELS_SYSTEM_TAG={{ SALT_MODELS_SYSTEM_TAG }}"
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300369 {%- endif %}
370 echo "======================================="
371 node_name: {{ HOSTNAME_CFG01 }}
372 retry: {count: 1, delay: 1}
373 skip_fail: false
374
Dennis Dmitriev06979442018-10-24 18:53:49 +0300375- description: "Upload {{ COOKIECUTTER_TEMPLATES_REPOSITORY_USER }} key"
376 upload:
377 local_path: {{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | dirname }}/
378 local_filename: {{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
379 remote_path: /tmp/
380 node_name: {{ HOSTNAME_CFG01 }}
381
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300382- description: Create cluster model from cookiecutter templates
383 cmd: |
384 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300385 set -x;
Tatyana Leontovich1ef60952018-12-19 00:36:50 +0200386 sudo apt-get install virtualenv -y
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300387 sudo apt-get install python-setuptools -y
Dennis Dmitrievb4b74032018-12-18 21:53:23 +0200388
389 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
390 . /root/venv-reclass-tools/bin/activate;
391 pip install -U pip
392
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300393 pip install cookiecutter
Dennis Dmitriev06979442018-10-24 18:53:49 +0300394
395 chmod 0600 /tmp/{{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
396 eval $(ssh-agent)
397 ssh-add /tmp/{{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300398 export GIT_SSL_NO_VERIFY=true; git clone {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} /root/cookiecutter-templates
sgudz4d816eb2017-11-13 11:58:05 +0200399
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300400 {%- if COOKIECUTTER_REF_CHANGE != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300401 pushd /root/cookiecutter-templates
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300402 git fetch {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
sgudz4d816eb2017-11-13 11:58:05 +0200403 popd
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300404 {%- elif COOKIECUTTER_TEMPLATE_COMMIT != '' %}
405 pushd /root/cookiecutter-templates
406 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
407 popd
Dennis Dmitriev713dce22018-07-03 11:47:46 +0300408 {%- elif COOKIECUTTER_TAG != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300409 pushd /root/cookiecutter-templates
Tatyana Leontovich819a6c82018-06-04 12:05:16 +0300410 git fetch --all --tags --prune
411 git checkout tags/{{ COOKIECUTTER_TAG }}
412 popd
413 {%- endif %}
414
Dennis Dmitrievddcea2f2018-12-18 21:21:11 +0200415 if [ -f /root/cookiecutter-templates/requirements.txt ]; then
416 pip install -r /root/cookiecutter-templates/requirements.txt
417 fi
418
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300419 mkdir -p /srv/salt/reclass/classes/cluster/
420 mkdir -p /srv/salt/reclass/classes/system/
421 mkdir -p /srv/salt/reclass/classes/service/
422 mkdir -p /srv/salt/reclass/nodes/_generated
423
424 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200425 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
426 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200427 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300428 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200429 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300430 {%- endif %}
431 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200432 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300433 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300434
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300435 # Replace firstly to an intermediate value to avoid intersection between
436 # already replaced and replacing networks.
437 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
438 # 192.168.10 -> 10.16.0 (generated network for admin)
439 # 10.16.0 -> <external network>
440 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300441 export REPLACE_DIRS="{{ CLUSTER_CONTEXT_PATH }} /root/cookiecutter-templates"
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300442 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
443 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
444 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
445 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300446
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300447 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
448 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
449 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
450 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 +0300451
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300452 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /root/cookiecutter-templates/cluster_product/)' %}
sgudz160b7302017-12-22 17:01:10 +0200453 for item in {{ items }}; do
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300454 python /root/cookiecutter-templates/generate.py \
455 --template /root/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300456 --config-file {{ CLUSTER_CONTEXT_PATH }} \
457 --output-dir /srv/salt/reclass/classes/cluster/;
458 done
459
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300460 export GIT_SSL_NO_VERIFY=true; git clone {{ SALT_MODELS_SYSTEM_REPOSITORY }} /srv/salt/reclass/classes/system/
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300461
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200462 # Create the cfg01 inventory file or use existing
463 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
464 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300465 classes:
466 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200467 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300468 EOF
469
470 node_name: {{ HOSTNAME_CFG01 }}
471 retry: {count: 1, delay: 1}
472 skip_fail: false
473
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300474- description: Modify generated model and reclass-system if necessary
475 cmd: |
476 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300477 set -x;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300478 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300479 pushd /srv/salt/reclass/classes/system/ && \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300480 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300481 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300482 {%- endfor %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300483 popd;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300484 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
485 pushd /srv/salt/reclass/classes/system/
486 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
487 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300488 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
489 pushd /srv/salt/reclass/classes/system/
490 git fetch --all --tags --prune
491 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
492 popd;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300493 {%- endif %}
494
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300495 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200496 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300497 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
498 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
499 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
500 {%- endif %}
501
502 node_name: {{ HOSTNAME_CFG01 }}
503 retry: {count: 1, delay: 1}
504 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +0300505
506- description: Restart salt-api
507 cmd: |
508 set -e;
509 systemctl restart salt-api
510
511 node_name: {{ HOSTNAME_CFG01 }}
512 retry: {count: 1, delay: 1}
513 skip_fail: false
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300514{%- endmacro %}
515
516
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300517{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
518{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300519
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200520- description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300521 cmd: |
522 set -e;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300523 mkdir -p /root/environment/;
524 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 +0300525
Vladimir Khlyunevf337c902018-12-06 12:29:24 +0400526 {%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300527 pushd /root/environment/environment_template &&
sgudzcced67d2017-10-11 15:56:09 +0300528 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
529 git checkout FETCH_HEAD &&
530 popd
Vladimir Khlyunevf337c902018-12-06 12:29:24 +0400531 {%- elif ENVIRONMENT_TEMPLATE_COMMIT != '' %}
532 pushd /root/environment/environment_template
533 git checkout {{ ENVIRONMENT_TEMPLATE_COMMIT }}
534 popd
535 {%- endif %}
536
sgudzcced67d2017-10-11 15:56:09 +0300537 node_name: {{ HOSTNAME_CFG01 }}
538 skip_fail: false
sgudzcced67d2017-10-11 15:56:09 +0300539
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300540{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200541- description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300542 upload:
543 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
544 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300545 remote_path: /root/environment/
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300546 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300547{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300548
Dennis Dmitriev1ddf6472018-11-25 22:30:12 +0200549- description: "Replace template addresses to actual environment addresses"
550 cmd: |
551 set -ex;
552 # Replace firstly to an intermediate value to avoid intersection between
553 # already replaced and replacing networks.
554 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
555 # 192.168.10 -> 10.16.0 (generated network for admin)
556 # 10.16.0 -> <external network>
557 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
558 export REPLACE_DIRS="/root/environment/"
559 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
560 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
561 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
562 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
563
564 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
565 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
566 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
567 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {} +
568 node_name: {{ HOSTNAME_CFG01 }}
569 retry: {count: 1, delay: 5}
570 skip_fail: false
571
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300572- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
573 cmd: |
574 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300575 set -x;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300576 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200577 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
578 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300579 pip install git+https://github.com/dis-xcom/reclass-tools;
580 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
581 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
582 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
583
Dennis Dmitriev6368f082018-02-23 13:30:30 -0500584 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
585 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
586 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 +0300587 fi;
588
589 node_name: {{ HOSTNAME_CFG01 }}
590 retry: {count: 1, delay: 5}
591 skip_fail: false
592
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200593- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300594 cmd: |
595 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200596 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 +0300597
598 node_name: {{ HOSTNAME_CFG01 }}
599 retry: {count: 1, delay: 5}
600 skip_fail: false
601
602- description: "[EXPERIMENTAL] Create environment model for virtual environment"
603 cmd: |
604 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300605 set -x;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200606 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300607 reclass-tools render --template-dir /root/environment/environment_template/ \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300608 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300609 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /root/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300610 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
611 node_name: {{ HOSTNAME_CFG01 }}
612 retry: {count: 1, delay: 5}
613 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300614
615- description: Modify generated model and reclass-system
616 cmd: |
617 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
618 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 +0400619 find ${REPLACE_DIRS} -type f -exec sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {} +
sgudz8c888ec2017-10-02 15:29:23 +0300620 node_name: {{ HOSTNAME_CFG01 }}
621 retry: {count: 1, delay: 1}
622 skip_fail: false
623
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300624{%- endmacro %}
625
626
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300627{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
628{#######################################################}
629- description: Configure reclass
630 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300631 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300632 set -x;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300633 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300634 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200635 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200636 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
637 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300638 apt-get clean; apt-get update;
639 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
640 declare -a formula_services=({{ FORMULA_SERVICES }});
641 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200642 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300643 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300644 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
645 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
646 done;
647 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
648 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
649 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
650
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200651 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300652 storage_type: yaml_fs
653 pretty_print: True
654 output: yaml
655 inventory_base_uri: /srv/salt/reclass
656 EOF
657 node_name: {{ HOSTNAME_CFG01 }}
658 retry: {count: 1, delay: 1}
659 skip_fail: false
660
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200661- 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 +0300662 cmd: |
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200663 # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top'
664 find /srv/salt/reclass/nodes/ -type f -not -name cfg01.{{ DOMAIN_NAME }}.yml -delete
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300665 node_name: {{ HOSTNAME_CFG01 }}
666 retry: {count: 1, delay: 5}
667 skip_fail: false
668
669- description: Configure salt adoptors on cfg01
670 cmd: |
671 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
672 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
673 node_name: {{ HOSTNAME_CFG01 }}
674 retry: {count: 1, delay: 1}
675 skip_fail: false
676
677- description: Show reclass-salt --top for cfg01 node
678 cmd: reclass-salt --top
679 node_name: {{ HOSTNAME_CFG01 }}
680 retry: {count: 1, delay: 5}
681 skip_fail: false
682
683- description: Restart salt-master service
ibumarskov712a6872018-04-25 09:22:15 +0400684 cmd: service salt-master restart;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300685 node_name: {{ HOSTNAME_CFG01 }}
686 retry: {count: 1, delay: 5}
687 skip_fail: false
688{%- endmacro %}
689
690
691{%- macro MACRO_INSTALL_SALT_MINIONS() %}
692{#######################################}
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200693{%- for ssh in config.underlay.ssh %}
694 {%- set salt_roles = [] %}
695 {%- for role in ssh['roles'] %}
696 {%- if role in config.salt_deploy.salt_roles %}
697 {%- set _ = salt_roles.append(role) %}
698 {%- endif %}
699 {%- endfor %}
700
701 {%- if salt_roles %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300702- description: Configure salt-minion on {{ ssh['node_name'] }}
703 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300704 set -ex;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300705 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitriev3fe24dd2018-07-20 18:38:57 +0300706 cat << EOF > /etc/salt/minion.d/minion.conf
707 id: $(hostname -s).{{ DOMAIN_NAME }}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300708 master: {{ config.salt.salt_master_host }}
709 EOF
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200710
711 # Configure ubuntu and salt repositories
712 which wget >/dev/null || (apt-get update; apt-get install -y wget);
713
714 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
715 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
716 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
717 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
718
719 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300720 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
721
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200722
723 apt-get clean
724 apt-get update
725
726 # Install salt-minion
Tatyana Leontovich47708552018-12-19 16:36:09 +0200727 apt-get install eatmydata -y;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300728 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200729 # Install common packages
730 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200731 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200732 # Restart salt-minion if it was already installed
733 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300734 node_name: {{ ssh['node_name'] }}
735 retry: {count: 1, delay: 1}
736 skip_fail: false
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200737 {%- else %}
738- description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }}
739 cmd: echo "SSH to $(hostname -f) passed"
740 node_name: {{ ssh['node_name'] }}
741 retry: {count: 1, delay: 1}
742 skip_fail: false
743 {%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300744
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200745{%- endfor %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300746
747- description: Accept salt keys from all the nodes
748 cmd: salt-key -A -y
749 node_name: {{ HOSTNAME_CFG01 }}
750 retry: {count: 1, delay: 5}
751 skip_fail: true
752{%- endmacro %}
753
754
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200755{%- macro MACRO_INSTALL_FORMULAS(FORMULA_SERVICES='') %}
756{#######################################################}
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300757- description: Install salt formulas
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200758 cmd: |
759 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300760 set -x;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200761 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
762 which wget > /dev/null || (apt-get update; apt-get install -y wget);
763 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
764 # echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
765 # wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
766 apt-get clean; apt-get update;
767 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
768 declare -a formula_services=({{ FORMULA_SERVICES }});
769 echo -e "\nInstalling all required salt formulas\n";
770 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300771 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200772 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
773 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
774 done;
775 node_name: {{ HOSTNAME_CFG01 }}
776 retry: {count: 1, delay: 1}
777 skip_fail: false
Dennis Dmitriev010f0292018-07-28 23:33:48 +0300778
779- description: Sync all salt resources on salt-master minion
780 cmd: salt-call saltutil.sync_all && sleep 5
781 node_name: {{ HOSTNAME_CFG01 }}
782 retry: {count: 1, delay: 5}
783 skip_fail: false
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200784{%- endmacro %}
785
786{%- macro MACRO_CONFIG_DAY01_SALT_MINION() %}
787{#######################################}
788- description: Configure salt-minion on {{ HOSTNAME_CFG01 }}
789 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300790 set -ex;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200791 export SALT_MASTER_MINION_ID={{ HOSTNAME_CFG01 }}
792 envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
793 service salt-minion restart
794
795 while true; do
796 salt-key | grep "$SALT_MASTER_MINION_ID" && break
797 sleep 5
798 done
799
800 sleep 5
801
802 for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do
803 salt-key -d $i -y
804 done
805 node_name: {{ HOSTNAME_CFG01 }}
806 retry: {count: 1, delay: 1}
807 skip_fail: false
808{%- endmacro %}
809
810
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300811{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
812{##################################################}
813
814{# Prepare salt services and nodes settings #}
815
sgudz6e797562018-10-22 12:27:09 +0300816- description: '*Workaround* of harcoded host from day01 grains'
817 cmd: salt-key -d cfg01.mcp-day01.local -y
818 node_name: {{ HOSTNAME_CFG01 }}
819 retry: {count: 1, delay: 1}
820 skip_fail: true
821
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300822- description: Run 'linux' formula on cfg01
823 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
824 node_name: {{ HOSTNAME_CFG01 }}
825 retry: {count: 3, delay: 5}
826 skip_fail: false
827
828- description: Run 'openssh' formula on cfg01
829 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300830 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300831 salt --hard-crash --state-output=mixed --state-verbose=False
832 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +0300833 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300834 node_name: {{ HOSTNAME_CFG01 }}
835 retry: {count: 3, delay: 5}
836 skip_fail: false
837
838- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
839 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
840 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
841 node_name: {{ HOSTNAME_CFG01 }}
842 retry: {count: 1, delay: 1}
843 skip_fail: false
844
845- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300846 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 +0300847 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300848 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300849 skip_fail: false
850
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400851{%- if SALT_FORMULAS_REFS != '' %}
852- description: Replace needed formulas to desired version
853 cmd: |
854 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300855 set -x;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400856 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
857 {% set formula = formula_set.split(':') %}
858 {% set formula_name = formula[0] %}
859 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300860 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400861 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
862 pushd {{ formula_dir }} &&
863 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
864 git checkout FETCH_HEAD &&
865 popd &&
866 if [ -d "{{ formula_dir }}" ]; then
867 echo "Going to replace packaged formula {{ formula_name }}" &&
868 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400869 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
870 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400871 else
872 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
873 fi
874 {%- endfor %}
875 node_name: {{ HOSTNAME_CFG01 }}
876 retry: {count: 1, delay: 10}
877 skip_fail: false
878{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300879
880- description: Refresh pillars on salt-master minion
881 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
882 node_name: {{ HOSTNAME_CFG01 }}
883 retry: {count: 1, delay: 5}
884 skip_fail: false
885
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300886- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300887 cmd: reclass-salt --top
888 node_name: {{ HOSTNAME_CFG01 }}
889 retry: {count: 1, delay: 5}
890 skip_fail: false
891
892- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300893 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 +0300894 node_name: {{ HOSTNAME_CFG01 }}
895 retry: {count: 1, delay: 5}
896 skip_fail: false
897
898- description: Configure linux on master
899 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
900 node_name: {{ HOSTNAME_CFG01 }}
901 retry: {count: 1, delay: 5}
902 skip_fail: false
903
904- description: Configure salt.minion on master
905 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
906 -C 'I@salt:master' state.sls salt.minion && sleep 10
907 node_name: {{ HOSTNAME_CFG01 }}
908 retry: {count: 3, delay: 10}
909 skip_fail: false
910
911- description: Run state 'salt' on master (for salt.api, etc)
912 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
913 -C 'I@salt:master' state.sls salt
914 node_name: {{ HOSTNAME_CFG01 }}
915 retry: {count: 3, delay: 10}
916 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +0300917
918- description: Restart salt-api after states
919 cmd: systemctl restart salt-api
920 node_name: {{ HOSTNAME_CFG01 }}
921 retry: {count: 3, delay: 10}
922 skip_fail: false
923
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300924{%- endmacro %}
925
Dennis Dmitriev85559962018-01-30 15:35:51 +0200926{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
927{#################################################################}
928
929- description: Refresh pillars before generating nodes
930 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
931 node_name: {{ HOSTNAME_CFG01 }}
932 retry: {count: 1, delay: 5}
933 skip_fail: false
934
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +0200935- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200936 cmd: |
937 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300938 set -x;
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200939 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
940 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 +0200941 node_name: {{ HOSTNAME_CFG01 }}
942 retry: {count: 1, delay: 5}
943 skip_fail: false
944
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300945- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
946 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
947 -C 'I@salt:master' state.sls reclass
948 node_name: {{ HOSTNAME_CFG01 }}
949 retry: {count: 1, delay: 5}
950 skip_fail: false
951
Dennis Dmitriev85559962018-01-30 15:35:51 +0200952{%- if RERUN_SALTMASTER_STATE %}
953- description: Regenerate salt.master states for the newly uploaded/created model
954 cmd: |
955 # Need to refresh installed formulas that are required in the model
956 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
957 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
958 node_name: {{ HOSTNAME_CFG01 }}
959 retry: {count: 1, delay: 5}
960 skip_fail: false
961{%- endif %}
962
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300963- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +0200964 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300965 node_name: {{ HOSTNAME_CFG01 }}
966 retry: {count: 1, delay: 5}
967 skip_fail: false
968
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300969- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300970 cmd: |
971 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300972 set -x;
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300973 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
974 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
975 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300976 node_name: {{ HOSTNAME_CFG01 }}
977 retry: {count: 1, delay: 5}
978 skip_fail: false
979
980- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300981 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300982 node_name: {{ HOSTNAME_CFG01 }}
983 retry: {count: 1, delay: 5}
984 skip_fail: false
985{%- endmacro %}
986
987
988{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
989{########################################}
990# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +0200991
992- description: Get linux kernel version from all minions
993 cmd: |
994 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
995 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
996 node_name: {{ HOSTNAME_CFG01 }}
997 retry: {count: 5, delay: 10}
998 skip_fail: false
999
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001000- description: Configure linux on other nodes
1001 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
1002 node_name: {{ HOSTNAME_CFG01 }}
1003 retry: {count: 5, delay: 10}
1004 skip_fail: false
1005
1006- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +03001007 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 +03001008 salt --hard-crash --state-output=mixed --state-verbose=False
1009 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +03001010 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001011 node_name: {{ HOSTNAME_CFG01 }}
1012 retry: {count: 1, delay: 5}
1013 skip_fail: false
1014
1015- description: Configure salt.minion on other nodes
1016 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 +04001017 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001018 node_name: {{ HOSTNAME_CFG01 }}
1019 retry: {count: 3, delay: 15}
1020 skip_fail: false
1021
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001022- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +04001023 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001024 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +04001025 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001026 skip_fail: false
1027
Victor Ryzhenkina06443e2018-03-15 17:25:19 +04001028- description: Update minion information
Dennis Dmitrievea291ee2018-03-16 12:27:43 +02001029 cmd: |
1030 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001031 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 60
Victor Ryzhenkina06443e2018-03-15 17:25:19 +04001032 node_name: {{ HOSTNAME_CFG01 }}
1033 retry: {count: 1, delay: 10}
1034 skip_fail: false
1035
Dennis Dmitriev14183db2018-03-01 15:14:12 +02001036- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
1037 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
1038 node_name: {{ HOSTNAME_CFG01 }}
1039 retry: {count: 1, delay: 10}
1040 skip_fail: false
1041
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001042- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001043 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001044 node_name: {{ HOSTNAME_CFG01 }}
1045 retry: {count: 3, delay: 15}
1046 skip_fail: false
1047
1048- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001049 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001050 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001051 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001052 skip_fail: false
1053
1054- description: Configure ntp and rsyslog on nodes
1055 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
1056 node_name: {{ HOSTNAME_CFG01 }}
1057 retry: {count: 1, delay: 10}
1058 skip_fail: false
Tatyana Leontovich529e4052018-07-09 18:30:48 +03001059
1060- description: Install and configure iptables if it is in pillar
1061 cmd: |
1062 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' match.pillar 'iptables:service' ; then
1063 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' state.sls iptables
1064 fi
1065 node_name: {{ HOSTNAME_CFG01 }}
1066 retry: {count: 1, delay: 10}
1067 skip_fail: false
1068
1069
1070- description: Install and configure logrotate if it is in pillar
1071 cmd: |
1072 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' match.pillar 'logrotate:server' ; then
1073 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' state.sls logrotate
1074 fi
1075 node_name: {{ HOSTNAME_CFG01 }}
1076 retry: {count: 1, delay: 10}
1077 skip_fail: false
1078
1079- description: Install and configure auditd if it is enabled
1080 cmd: |
1081 if salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" match.pillar 'auditd:service'; then
1082 salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" state.sls auditd
1083 fi
1084 node_name: {{ HOSTNAME_CFG01 }}
1085 retry: {count: 1, delay: 10}
1086 skip_fail: false
1087
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02001088{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001089
1090
1091{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
1092{#########################################}
1093
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001094- description: '*Workaround: Load bonding module before call state.linux'
1095 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
1096 node_name: {{ HOSTNAME_CFG01 }}
1097 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +03001098 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001099
1100- description: '*Workaround* install bridge-utils before running linux formula'
1101 # The formula removes default route and then tries to install the package, fails.
1102 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
1103 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
1104 node_name: {{ HOSTNAME_CFG01 }}
1105 retry: {count: 1, delay: 5}
1106 skip_fail: false
1107
1108{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001109
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001110
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001111{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001112{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001113
1114- description: Set k8s deploy parameters
1115 cmd: |
1116 {% for k8s_opt, value in config.k8s_deploy.items() %}
1117 {% if value|string() %}
1118 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
1119 {% endif %}
1120 {% endfor %}
1121 node_name: {{ HOSTNAME_CFG01 }}
1122 retry: {count: 1, delay: 1}
1123 skip_fail: false
1124
1125{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001126
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001127
1128{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
1129{#############################################}
1130- description: Set SL docker images deploy parameters
1131 cmd: |
1132 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
1133 {%- for sl_opt, value in config.sl_deploy.items() %}
1134 {%- if value|string() %}
1135 {%- if OVERRIDES_FILENAME %}
1136 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
1137 {%- else %}
1138 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
1139 {%- endif %}
1140 {%- endif %}
1141 {%- endfor %}
1142 salt '*' saltutil.refresh_pillar;
1143 sleep 10
1144 node_name: {{ HOSTNAME_CFG01 }}
1145 retry: {count: 1, delay: 1}
1146 skip_fail: false
1147{%- endmacro %}
1148
1149
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001150{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001151{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001152
1153{% for ssh in config.underlay.ssh %}
1154{% if ssh["node_name"].startswith("cmp") %}
1155{% set node_hostname = ssh["node_name"].split('.')[0] %}
1156- description: Register compute {{ ssh['node_name'] }}
1157 cmd: |
1158 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
1159 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
1160 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +04001161 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001162 export config_host={{ config.salt.salt_master_host }}
1163 export node_domain={{ DOMAIN_NAME }}
1164 export nodes_os="xenial"
1165 export node_hostname={{ node_hostname }}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001166 export saltversion={{ SALT_VERSION }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001167 set -xe
1168 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
1169 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
1170 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
1171 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
1172
1173 # Add wrapper to apt-get to avoid race conditions
1174 # with cron jobs running 'unattended-upgrades' script
1175 aptget_wrapper() {
1176 local apt_wrapper_timeout=300
1177 local start_time=$(date '+%s')
1178 local fin_time=$((start_time + apt_wrapper_timeout))
1179 while true; do
1180 if (( "$(date '+%s')" > fin_time )); then
1181 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
1182 fi
1183 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
1184 echo "Waiting while another apt/dpkg process releases locks ..."
1185 sleep 30
1186 continue
1187 else
1188 apt-get $@
1189 break
1190 fi
1191 done
1192 }
1193
1194 # Set default salt version
1195 if [ -z "$saltversion" ]; then
Tatyana Leontovich14e201d2018-07-05 13:28:54 +03001196 saltversion="2017.7"
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001197 fi
1198 echo "Using Salt version $saltversion"
1199
1200 echo "Preparing base OS ..."
1201
1202 case "$node_os" in
1203 trusty)
1204 # workaround for old cloud-init only configuring the first iface
1205 iface_config_dir="/etc/network/interfaces"
1206 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
1207
1208 for iface in $ifaces; do
1209 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
1210 done
1211
1212 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1213
1214 # SUGGESTED UPDATE:
1215 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1216 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1217 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1218 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1219 #install_salt_minion_pkg
1220
1221 # DEPRECATED:
1222 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1223 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1224
1225 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
1226 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1227
1228 aptget_wrapper clean
1229 aptget_wrapper update
1230 aptget_wrapper install -y salt-common
1231 aptget_wrapper install -y salt-minion
1232 ;;
1233 xenial)
1234
1235 # workaround for new cloud-init setting all interfaces statically
1236 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
1237
1238 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1239
1240 # SUGGESTED UPDATE:
1241 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1242 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1243 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1244 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1245 #install_salt_minion_pkg
1246
1247 # DEPRECATED:
1248 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1249 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1250
1251 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
1252 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1253
1254 aptget_wrapper clean
1255 aptget_wrapper update
1256 aptget_wrapper install -y salt-minion
1257 ;;
1258 rhel|centos|centos7|centos7|rhel6|rhel7)
1259 yum install -y git
1260 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1261 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1262 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1263 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1264 install_salt_minion_pkg
1265 ;;
1266 *)
1267 msg="OS '$node_os' is not supported."
1268 esac
1269
1270 echo "Configuring Salt minion ..."
1271 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
1272 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
1273
1274 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
1275
1276 sleep 1
1277
1278 echo "Classifying node ..."
1279 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
1280 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1281 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1282 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1283 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1284 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1285
1286 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1287 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1288 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1289 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1290 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1291
1292 if [ "$node_network05_iface" != "" ]; then
1293 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
1294 fi
1295
1296 # find more parameters (every env starting param_)
1297 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
1298 if [ "$more_params" != "" ]; then
1299 echo "Additional params: $more_params"
1300 more_params=", $more_params"
1301 fi
1302
1303 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}}"
1304
1305 sleep 5
1306
1307 salt-call saltutil.sync_all
1308 salt-call mine.flush
1309 salt-call mine.update
1310 node_name: {{ ssh['node_name'] }}
1311 retry: {count: 1, delay: 1}
1312 skip_fail: false
1313{%- endif %}
1314{%- endfor %}
1315
1316- description: Refresh pillars on all minions
1317 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1318 node_name: {{ HOSTNAME_CFG01 }}
1319 retry: {count: 1, delay: 5}
1320 skip_fail: false
1321
1322- description: Sync all salt resources
1323 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1324 node_name: {{ HOSTNAME_CFG01 }}
1325 retry: {count: 1, delay: 5}
1326 skip_fail: false
1327
sgudz160b7302017-12-22 17:01:10 +02001328{%- endmacro %}
sgudz09e9aa92018-04-12 12:31:53 +03001329
1330{%- macro RUN_NEW_TEMPEST() %}
1331{###################################}
1332
1333- description: Upload tempest template
1334 upload:
1335 local_path: {{ config.salt_deploy.templates_dir }}
1336 local_filename: runtest.yml
1337 remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/
1338 node_name: {{ HOSTNAME_CFG01 }}
1339 skip_fail: False
1340
1341- description: Include class with tempest template into cfg node
1342 cmd: |
1343 sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml;
1344 salt 'cfg01*' saltutil.refresh_pillar;
1345 salt 'cfg01*' saltutil.sync_all;
1346 node_name: {{ HOSTNAME_CFG01 }}
1347 retry: {count: 1, delay: 10}
1348 skip_fail: false
1349
Oleksii Butenko2e8e8ee2018-06-21 11:10:13 +03001350- description: Execute salt.minion on config node
1351 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False state.sls salt.minion;
1352 node_name: {{ HOSTNAME_CFG01 }}
1353 retry: {count: 1, delay: 5}
1354 skip_fail: false
1355
1356- description: Test ping
1357 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False test.ping;
1358 node_name: {{ HOSTNAME_CFG01 }}
1359 retry: {count: 1, delay: 5}
1360 skip_fail: false
1361
sgudz09e9aa92018-04-12 12:31:53 +03001362- description: Create flavors for tests
1363 cmd: |
1364 salt 'cfg01*' state.sls nova.client;
1365 node_name: {{ HOSTNAME_CFG01 }}
1366 retry: {count: 1, delay: 5}
1367 skip_fail: false
1368
1369- description: Create networks for tests
1370 cmd: |
1371 salt 'cfg01*' state.sls neutron.client;
1372 node_name: {{ HOSTNAME_CFG01 }}
1373 retry: {count: 1, delay: 5}
1374 skip_fail: false
1375
1376- description: Upload cirros image
1377 cmd: |
1378 salt 'cfg01*' state.sls glance.client;
1379 node_name: {{ HOSTNAME_CFG01 }}
1380 retry: {count: 1, delay: 5}
1381 skip_fail: false
1382
1383- description: Generate tempest config
1384 cmd: |
1385 salt 'cfg01*' state.sls runtest;
1386 node_name: {{ HOSTNAME_CFG01 }}
1387 retry: {count: 1, delay: 5}
1388 skip_fail: false
1389
1390- description: Run tempest from new docker image
1391 cmd: |
Oleksii Butenko71d76f32018-06-05 17:46:34 +03001392 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 +03001393 node_name: {{ HOSTNAME_GTW01 }}
1394 retry: {count: 1, delay: 30}
1395 skip_fail: true
1396
1397- description: Download xml results
1398 download:
1399 remote_path: /root/test/
1400 remote_filename: "report_*.xml"
1401 local_path: {{ os_env('PWD') }}
1402 node_name: {{ HOSTNAME_GTW01 }}
1403 skip_fail: true
1404
1405{%- endmacro %}
Oleksii Butenko5cd0a162018-06-14 18:18:10 +03001406
1407{%- macro INSTALL_DOCKER_ON_GTW() %}
1408{###################################}
1409
1410- description: Install docker.io on gtw
1411 cmd: salt-call cmd.run 'apt-get install docker.io -y'
1412 node_name: {{ HOSTNAME_GTW01 }}
1413 retry: {count: 1, delay: 30}
1414 skip_fail: false
1415
1416- description: Enable forward policy
1417 cmd: iptables --policy FORWARD ACCEPT
1418 node_name: {{ HOSTNAME_GTW01 }}
1419 retry: {count: 1, delay: 30}
1420 skip_fail: false
1421
1422{%- endmacro %}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001423
1424{%- macro MACRO_CHECK_SALT_VERSION_ON_NODES() %}
1425{#####################################################}
1426
1427{%- for ssh in config.underlay.ssh %}
1428 {%- set salt_roles = [] %}
1429 {%- for role in ssh['roles'] %}
1430 {%- if role in config.salt_deploy.salt_roles %}
1431 {%- set _ = salt_roles.append(role) %}
1432 {%- endif %}
1433 {%- endfor %}
1434
1435 {%- if salt_roles %}
1436- description: 'Check salt version is as expected'
1437 cmd: salt-call test.version | grep {{ SALT_VERSION }}
1438 node_name: {{ ssh['node_name'] }}
1439 retry: {count: 1, delay: 1}
1440 skip_fail: false
1441 {%- endif %}
1442
1443{%- endfor %}
1444{%- endmacro %}
1445
1446{%- macro MACRO_CHECK_SALT_VERSION_SERVICES_ON_CFG() %}
1447{#####################################################}
1448
1449- description: 'Check salt-api, salt-master and salt-minion version'
1450 cmd: |
1451 salt-master --version | grep {{ SALT_VERSION }};
1452 salt-minion --version | grep {{ SALT_VERSION }};
1453 salt-api --version | grep {{ SALT_VERSION }};
1454 node_name: {{ HOSTNAME_CFG01 }}
1455 retry: {count: 1, delay: 5}
1456 skip_fail: false
1457
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001458{%- endmacro %}