blob: 907f8a05734497ab9b9df8308bc4a24d1a28c99b [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 #}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +03008{% set SALT_MODELS_SYSTEM_REPOSITORY = os_env('SALT_MODELS_SYSTEM_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/reclass-system') %}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02009{% set SALT_MODELS_SYSTEM_COMMIT = os_env('SALT_MODELS_SYSTEM_COMMIT','') %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +030010{% set SALT_MODELS_SYSTEM_REF_CHANGE = os_env('SALT_MODELS_SYSTEM_REF_CHANGE','') %}
sgudz4d816eb2017-11-13 11:58:05 +020011{% set COOKIECUTTER_REF_CHANGE = os_env('COOKIECUTTER_REF_CHANGE','') %}
sgudza399dc72018-01-18 17:13:48 +020012{% set COOKIECUTTER_TEMPLATE_COMMIT = os_env('COOKIECUTTER_TEMPLATE_COMMIT','') %}
sgudzcced67d2017-10-11 15:56:09 +030013{% set ENVIRONMENT_TEMPLATE_REF_CHANGE = os_env('ENVIRONMENT_TEMPLATE_REF_CHANGE','') %}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020014
Dennis Dmitriev492813e2017-08-09 15:08:58 +030015{% set REPOSITORY_SUITE = os_env('REPOSITORY_SUITE', 'testing') %}
Dennis Dmitrievcf777802018-02-14 18:09:55 +020016{% set FORMULA_REPOSITORY = os_env('FORMULA_REPOSITORY', 'deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME} ' + REPOSITORY_SUITE + ' salt extra') %}
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020017{% set FORMULA_GPG = os_env('FORMULA_GPG', 'http://apt.mirantis.com/public.gpg') %}
Dennis Dmitrievcf777802018-02-14 18:09:55 +020018{% set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME}/salt/2016.3 " + REPOSITORY_SUITE + " main") %}
19{% set SALT_GPG = os_env('SALT_GPG', 'http://apt.mirantis.com/public.gpg') %}
20{% set UBUNTU_REPOSITORY = os_env('UBUNTU_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME} main restricted universe") %}
21{% 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") %}
22{% 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 Dmitriev492813e2017-08-09 15:08:58 +030023
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020024{# Address pools for reclass cluster model are taken in the following order:
25 # 1. environment variables,
26 # 2. config.underlay.address_pools based on fuel-devops address pools
27 # (see generated '.ini' file after underlay is created),
28 # 3. defaults #}
29{% set address_pools = config.underlay.address_pools %}
30{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
31{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
32{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
33{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
34{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
35{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
36{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
37{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
38
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040039{# Format for formula replacement:
40 # space separated string:
41 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
42
43{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
44{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.net/salt-formulas') %}
45
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040046# Needed for using different models in different templates
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020047{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040048
Dennis Dmitriev492813e2017-08-09 15:08:58 +030049
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020050{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
51{#####################################################}
52
53- description: 'Configure key on nodes and install packages'
54 cmd: |
55 rm -rf trusted* ;
56 rm -rf /etc/apt/sources.list ;
Dennis Dmitrievcf777802018-02-14 18:09:55 +020057 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020058 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
59 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
60 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
61 wget -O - "{{ SALT_GPG }}" | apt-key add -;
62 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
63 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
64 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
65 eatmydata apt-get clean && apt-get update;
Dennis Dmitriev01d5e372018-03-15 23:29:29 +020066 sync;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020067 node_name: {{ NODE_NAME }}
68 retry: {count: 1, delay: 5}
69 skip_fail: false
70
71{%- endmacro %}
72
73
Dennis Dmitriev492813e2017-08-09 15:08:58 +030074{%- macro MACRO_INSTALL_SALT_MASTER() %}
75{######################################}
76- description: Installing salt master on cfg01
Dennis Dmitrievcf777802018-02-14 18:09:55 +020077 cmd: |
78 which wget >/dev/null || (apt-get update; apt-get install -y wget);
79 # Configure ubuntu and salt repositories
80 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
81 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
82 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
83 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
84
85 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
86 wget -O - {{ FORMULA_GPG }} | apt-key add -;
87 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
88 wget -O - {{ SALT_GPG }} | apt-key add -;
89
90 apt-get clean
91 apt-get update
92
93 # Install salt-master and reclass
94 eatmydata apt-get install -y --allow-unauthenticated reclass salt-master
95 # Install common packages
Dennis Dmitrievf88fc7d2018-02-20 15:40:08 +020096 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 +020097 sync;
Dennis Dmitriev492813e2017-08-09 15:08:58 +030098 node_name: {{ HOSTNAME_CFG01 }}
99 retry: {count: 1, delay: 1}
100 skip_fail: false
101
Dennis Dmitrievda9be462018-01-24 21:20:09 +0200102- description: Remove any existing minion keys
103 cmd: salt-key -y -D || true
104 node_name: {{ HOSTNAME_CFG01 }}
105 retry: {count: 1, delay: 1}
106 skip_fail: false
107
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300108- description: Configure salt-master on cfg01
109 cmd: |
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200110 cat << 'EOF' > /etc/salt/master.d/master.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300111 file_roots:
112 base:
113 - /usr/share/salt-formulas/env
114 pillar_opts: False
115 open_mode: True
116 reclass: &reclass
117 storage_type: yaml_fs
118 inventory_base_uri: /srv/salt/reclass
119 ext_pillar:
120 - reclass: *reclass
121 master_tops:
122 reclass: *reclass
123 EOF
124 node_name: {{ HOSTNAME_CFG01 }}
125 retry: {count: 1, delay: 1}
126 skip_fail: false
127
128- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300129 cmd: |
130 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200131 #touch /root/.git_trusted_certs.pem;
132 #for server in github.com; do \
133 # openssl s_client -showcerts -connect $server:443 </dev/null \
134 # | openssl x509 -outform PEM \
135 # >> /root/.git_trusted_certs.pem;
136 #done;
137 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
138 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
139 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300140 node_name: {{ HOSTNAME_CFG01 }}
141 retry: {count: 1, delay: 1}
142 skip_fail: false
143{%- endmacro %}
144
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300145{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false) %}
146{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300147{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
148
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300149- description: Clone reclass models with submodules
150 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300151 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200152 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200153 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200154
155 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
156 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 +0200157 rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200158
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200159 pushd /srv/salt/reclass;
160 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
161 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200162 {%- if SALT_MODELS_REF_CHANGE != '' %}
163 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200164 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200165 {%- endfor %}
166 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200167 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200168 {%- endif %}
169 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200170 pushd classes/system/;
171 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
172 popd;
sgudz4d816eb2017-11-13 11:58:05 +0200173 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300174 pushd classes/system/ && \
175 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200176 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300177 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200178 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200179 {%- endif %}
180 popd;
181 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300182 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200183
184 # Replace firstly to an intermediate value to avoid intersection between
185 # already replaced and replacing networks.
186 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
187 # 192.168.10 -> 10.16.0 (generated network for admin)
188 # 10.16.0 -> <external network>
189 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300190 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200191 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10/==IPV4_NET_ADMIN_PREFIX==/g' {} +
192 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10/==IPV4_NET_CONTROL_PREFIX==/g' {} +
193 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0/==IPV4_NET_TENANT_PREFIX==/g' {} +
194 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200195
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200196 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
197 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
198 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
199 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 +0200200
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300201 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200202
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300203 {%- if IS_CONTRAIL_LAB %}
204 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300205 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 +0300206 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 +0300207 {%- endif %}
208
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200209 # Override some context parameters
210 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
211 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
212 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
213
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200214 # Create the cfg01 inventory file or use existing
215 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
216 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300217 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400218 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300219 parameters:
220 _param:
221 linux_system_codename: xenial
222 reclass_data_revision: master
223 linux:
224 system:
225 name: cfg01
226 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200227 reclass:
228 storage:
229 data_source:
230 engine: local
231 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300232
233 # Show the changes to the console
234 cd /srv/salt/reclass/; git diff
235 node_name: {{ HOSTNAME_CFG01 }}
236 retry: {count: 1, delay: 1}
237 skip_fail: false
238{%- endmacro %}
239
240
sgudz160b7302017-12-22 17:01:10 +0200241{%- 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 +0300242{###################################################################}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300243{%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200244- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300245 upload:
246 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
247 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300248 remote_path: /tmp/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300249 node_name: {{ HOSTNAME_CFG01 }}
250
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300251- description: Create cluster model from cookiecutter templates
252 cmd: |
253 set -e;
254 pip install cookiecutter
255 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates /tmp/cookiecutter-templates
sgudz4d816eb2017-11-13 11:58:05 +0200256
sgudza399dc72018-01-18 17:13:48 +0200257 {%- if COOKIECUTTER_TEMPLATE_COMMIT != '' %}
258 pushd /tmp/cookiecutter-templates
259 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
260 popd
261 {%- endif %}
262
sgudz4d816eb2017-11-13 11:58:05 +0200263 {%- if COOKIECUTTER_REF_CHANGE != '' %}
264 pushd /tmp/cookiecutter-templates
265 git fetch https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
266 popd
267 {%- endif %}
268
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300269 mkdir -p /srv/salt/reclass/classes/cluster/
270 mkdir -p /srv/salt/reclass/classes/system/
271 mkdir -p /srv/salt/reclass/classes/service/
272 mkdir -p /srv/salt/reclass/nodes/_generated
273
274 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200275 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
276 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200277 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300278 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200279 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300280 {%- endif %}
281 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200282 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300283 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300284
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300285 # Replace firstly to an intermediate value to avoid intersection between
286 # already replaced and replacing networks.
287 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
288 # 192.168.10 -> 10.16.0 (generated network for admin)
289 # 10.16.0 -> <external network>
290 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
291 sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
292 sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
293 sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200294 sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300295
Dennis Dmitriev39e64bd2017-09-21 22:37:40 +0300296 sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
297 sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
298 sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200299 sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300300
sgudz160b7302017-12-22 17:01:10 +0200301 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /tmp/cookiecutter-templates/cluster_product/)' %}
302 for item in {{ items }}; do
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300303 python /tmp/cookiecutter-templates/generate.py \
sgudz160b7302017-12-22 17:01:10 +0200304 --template /tmp/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300305 --config-file {{ CLUSTER_CONTEXT_PATH }} \
306 --output-dir /srv/salt/reclass/classes/cluster/;
307 done
308
309 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/
310
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200311 # Create the cfg01 inventory file or use existing
312 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
313 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300314 classes:
315 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200316 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300317 EOF
318
319 node_name: {{ HOSTNAME_CFG01 }}
320 retry: {count: 1, delay: 1}
321 skip_fail: false
322
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300323- description: Modify generated model and reclass-system if necessary
324 cmd: |
325 set -e;
326 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
327 pushd /srv/salt/reclass/classes/system/
328 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
329 popd
sgudz4d816eb2017-11-13 11:58:05 +0200330 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300331 pushd /srv/salt/reclass/classes/system/
332 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
333 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD
334 {%- endfor %}
335 popd
336 {%- endif %}
337
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300338 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200339 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300340 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
341 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
342 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
343 {%- endif %}
344
345 node_name: {{ HOSTNAME_CFG01 }}
346 retry: {count: 1, delay: 1}
347 skip_fail: false
348{%- endmacro %}
349
350
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300351{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
352{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300353
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200354- description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300355 cmd: |
356 set -e;
357 mkdir -p /tmp/environment/;
358 export GIT_SSL_NO_VERIFY=true; git clone https://github.com/Mirantis/environment-template /tmp/environment/environment_template
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300359 node_name: {{ HOSTNAME_CFG01 }}
360 skip_fail: false
361
sgudzcced67d2017-10-11 15:56:09 +0300362{%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
363- description: Fetch changes for environment templates
364 cmd: |
365 set -e;
366 pushd /tmp/environment/environment_template &&
367 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
368 git checkout FETCH_HEAD &&
369 popd
370 node_name: {{ HOSTNAME_CFG01 }}
371 skip_fail: false
372{%- endif %}
373
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300374{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200375- description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300376 upload:
377 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
378 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
379 remote_path: /tmp/environment/
380 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300381{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300382
383- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
384 cmd: |
385 set -e;
386 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200387 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
388 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300389 pip install git+https://github.com/dis-xcom/reclass-tools;
390 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
391 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
392 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
393
Dennis Dmitriev6368f082018-02-23 13:30:30 -0500394 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
395 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
396 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 +0300397 fi;
398
399 node_name: {{ HOSTNAME_CFG01 }}
400 retry: {count: 1, delay: 5}
401 skip_fail: false
402
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200403- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300404 cmd: |
405 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200406 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 +0300407
408 node_name: {{ HOSTNAME_CFG01 }}
409 retry: {count: 1, delay: 5}
410 skip_fail: false
411
412- description: "[EXPERIMENTAL] Create environment model for virtual environment"
413 cmd: |
414 set -e;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200415 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300416 reclass-tools render --template-dir /tmp/environment/environment_template/ \
417 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitrievd55a8562017-09-28 22:12:09 +0300418 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /tmp/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300419 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
420 node_name: {{ HOSTNAME_CFG01 }}
421 retry: {count: 1, delay: 5}
422 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300423
424- description: Modify generated model and reclass-system
425 cmd: |
426 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
427 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
428 node_name: {{ HOSTNAME_CFG01 }}
429 retry: {count: 1, delay: 1}
430 skip_fail: false
431
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300432{%- endmacro %}
433
434
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300435{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
436{#######################################################}
437- description: Configure reclass
438 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300439 set -e;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300440 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300441 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200442 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200443 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
444 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300445 apt-get clean; apt-get update;
446 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
447 declare -a formula_services=({{ FORMULA_SERVICES }});
448 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200449 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300450 for formula_service in "${formula_services[@]}"; do
451 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
452 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
453 done;
454 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
455 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
456 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
457
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200458 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300459 storage_type: yaml_fs
460 pretty_print: True
461 output: yaml
462 inventory_base_uri: /srv/salt/reclass
463 EOF
464 node_name: {{ HOSTNAME_CFG01 }}
465 retry: {count: 1, delay: 1}
466 skip_fail: false
467
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200468- 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 +0300469 cmd: |
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200470 # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top'
471 find /srv/salt/reclass/nodes/ -type f -not -name cfg01.{{ DOMAIN_NAME }}.yml -delete
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300472 node_name: {{ HOSTNAME_CFG01 }}
473 retry: {count: 1, delay: 5}
474 skip_fail: false
475
476- description: Configure salt adoptors on cfg01
477 cmd: |
478 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
479 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
480 node_name: {{ HOSTNAME_CFG01 }}
481 retry: {count: 1, delay: 1}
482 skip_fail: false
483
484- description: Show reclass-salt --top for cfg01 node
485 cmd: reclass-salt --top
486 node_name: {{ HOSTNAME_CFG01 }}
487 retry: {count: 1, delay: 5}
488 skip_fail: false
489
490- description: Restart salt-master service
491 cmd: systemctl restart salt-master;
492 node_name: {{ HOSTNAME_CFG01 }}
493 retry: {count: 1, delay: 5}
494 skip_fail: false
495{%- endmacro %}
496
497
498{%- macro MACRO_INSTALL_SALT_MINIONS() %}
499{#######################################}
500{% for ssh in config.underlay.ssh %}
501- description: Configure salt-minion on {{ ssh['node_name'] }}
502 cmd: |
503 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200504 cat << "EOF" > /etc/salt/minion.d/minion.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300505 id: {{ ssh['node_name'] }}
506 master: {{ config.salt.salt_master_host }}
507 EOF
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200508
509 # Configure ubuntu and salt repositories
510 which wget >/dev/null || (apt-get update; apt-get install -y wget);
511
512 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
513 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
514 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
515 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
516
517 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
518 wget -O - {{ SALT_GPG }} | apt-key add -;
519
520 apt-get clean
521 apt-get update
522
523 # Install salt-minion
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300524 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200525 # Install common packages
526 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200527 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200528 # Restart salt-minion if it was already installed
529 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300530 node_name: {{ ssh['node_name'] }}
531 retry: {count: 1, delay: 1}
532 skip_fail: false
533{% endfor %}
534
535
536- description: Accept salt keys from all the nodes
537 cmd: salt-key -A -y
538 node_name: {{ HOSTNAME_CFG01 }}
539 retry: {count: 1, delay: 5}
540 skip_fail: true
541{%- endmacro %}
542
543
544{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
545{##################################################}
546
547{# Prepare salt services and nodes settings #}
548
549- description: Run 'linux' formula on cfg01
550 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
551 node_name: {{ HOSTNAME_CFG01 }}
552 retry: {count: 3, delay: 5}
553 skip_fail: false
554
555- description: Run 'openssh' formula on cfg01
556 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300557 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300558 salt --hard-crash --state-output=mixed --state-verbose=False
559 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300560 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300561 node_name: {{ HOSTNAME_CFG01 }}
562 retry: {count: 3, delay: 5}
563 skip_fail: false
564
565- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
566 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
567 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
568 node_name: {{ HOSTNAME_CFG01 }}
569 retry: {count: 1, delay: 1}
570 skip_fail: false
571
572- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300573 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 +0300574 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300575 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300576 skip_fail: false
577
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400578{%- if SALT_FORMULAS_REFS != '' %}
579- description: Replace needed formulas to desired version
580 cmd: |
581 set -e;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400582 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
583 {% set formula = formula_set.split(':') %}
584 {% set formula_name = formula[0] %}
585 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300586 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400587 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
588 pushd {{ formula_dir }} &&
589 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
590 git checkout FETCH_HEAD &&
591 popd &&
592 if [ -d "{{ formula_dir }}" ]; then
593 echo "Going to replace packaged formula {{ formula_name }}" &&
594 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400595 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
596 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400597 else
598 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
599 fi
600 {%- endfor %}
601 node_name: {{ HOSTNAME_CFG01 }}
602 retry: {count: 1, delay: 10}
603 skip_fail: false
604{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300605
606- description: Refresh pillars on salt-master minion
607 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
608 node_name: {{ HOSTNAME_CFG01 }}
609 retry: {count: 1, delay: 5}
610 skip_fail: false
611
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300612- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300613 cmd: reclass-salt --top
614 node_name: {{ HOSTNAME_CFG01 }}
615 retry: {count: 1, delay: 5}
616 skip_fail: false
617
618- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300619 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 +0300620 node_name: {{ HOSTNAME_CFG01 }}
621 retry: {count: 1, delay: 5}
622 skip_fail: false
623
624- description: Configure linux on master
625 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
626 node_name: {{ HOSTNAME_CFG01 }}
627 retry: {count: 1, delay: 5}
628 skip_fail: false
629
630- description: Configure salt.minion on master
631 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
632 -C 'I@salt:master' state.sls salt.minion && sleep 10
633 node_name: {{ HOSTNAME_CFG01 }}
634 retry: {count: 3, delay: 10}
635 skip_fail: false
636
637- description: Run state 'salt' on master (for salt.api, etc)
638 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
639 -C 'I@salt:master' state.sls salt
640 node_name: {{ HOSTNAME_CFG01 }}
641 retry: {count: 3, delay: 10}
642 skip_fail: false
643{%- endmacro %}
644
Dennis Dmitriev85559962018-01-30 15:35:51 +0200645{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
646{#################################################################}
647
648- description: Refresh pillars before generating nodes
649 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
650 node_name: {{ HOSTNAME_CFG01 }}
651 retry: {count: 1, delay: 5}
652 skip_fail: false
653
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +0200654- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200655 cmd: |
656 set -e
657 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
658 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 +0200659 node_name: {{ HOSTNAME_CFG01 }}
660 retry: {count: 1, delay: 5}
661 skip_fail: false
662
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300663- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
664 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
665 -C 'I@salt:master' state.sls reclass
666 node_name: {{ HOSTNAME_CFG01 }}
667 retry: {count: 1, delay: 5}
668 skip_fail: false
669
Dennis Dmitriev85559962018-01-30 15:35:51 +0200670{%- if RERUN_SALTMASTER_STATE %}
671- description: Regenerate salt.master states for the newly uploaded/created model
672 cmd: |
673 # Need to refresh installed formulas that are required in the model
674 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
675 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
676 node_name: {{ HOSTNAME_CFG01 }}
677 retry: {count: 1, delay: 5}
678 skip_fail: false
679{%- endif %}
680
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300681- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +0200682 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300683 node_name: {{ HOSTNAME_CFG01 }}
684 retry: {count: 1, delay: 5}
685 skip_fail: false
686
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300687- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300688 cmd: |
689 set -e
690 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
691 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
692 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300693 node_name: {{ HOSTNAME_CFG01 }}
694 retry: {count: 1, delay: 5}
695 skip_fail: false
696
697- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300698 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300699 node_name: {{ HOSTNAME_CFG01 }}
700 retry: {count: 1, delay: 5}
701 skip_fail: false
702{%- endmacro %}
703
704
705{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
706{########################################}
707# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +0200708
709- description: Get linux kernel version from all minions
710 cmd: |
711 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
712 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
713 node_name: {{ HOSTNAME_CFG01 }}
714 retry: {count: 5, delay: 10}
715 skip_fail: false
716
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300717- description: Configure linux on other nodes
718 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
719 node_name: {{ HOSTNAME_CFG01 }}
720 retry: {count: 5, delay: 10}
721 skip_fail: false
722
723- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300724 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 +0300725 salt --hard-crash --state-output=mixed --state-verbose=False
726 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
727 yes/' /etc/ssh/sshd_config && service ssh reload"
728 node_name: {{ HOSTNAME_CFG01 }}
729 retry: {count: 1, delay: 5}
730 skip_fail: false
731
732- description: Configure salt.minion on other nodes
733 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 +0400734 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300735 node_name: {{ HOSTNAME_CFG01 }}
736 retry: {count: 3, delay: 15}
737 skip_fail: false
738
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400739- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400740 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400741 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400742 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400743 skip_fail: false
744
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400745- description: Update minion information
Dennis Dmitriev4e915dd2018-03-15 22:17:40 +0200746 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 15
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400747 node_name: {{ HOSTNAME_CFG01 }}
748 retry: {count: 1, delay: 10}
749 skip_fail: false
750
Dennis Dmitriev14183db2018-03-01 15:14:12 +0200751- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
752 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
753 node_name: {{ HOSTNAME_CFG01 }}
754 retry: {count: 1, delay: 10}
755 skip_fail: false
756
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300757- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400758 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300759 node_name: {{ HOSTNAME_CFG01 }}
760 retry: {count: 3, delay: 15}
761 skip_fail: false
762
763- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400764 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300765 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400766 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300767 skip_fail: false
768
769- description: Configure ntp and rsyslog on nodes
770 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
771 node_name: {{ HOSTNAME_CFG01 }}
772 retry: {count: 1, delay: 10}
773 skip_fail: false
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200774{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300775
776
777{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
778{#########################################}
779
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300780- description: '*Workaround: Load bonding module before call state.linux'
781 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
782 node_name: {{ HOSTNAME_CFG01 }}
783 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +0300784 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300785
786- description: '*Workaround* install bridge-utils before running linux formula'
787 # The formula removes default route and then tries to install the package, fails.
788 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
789 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
790 node_name: {{ HOSTNAME_CFG01 }}
791 retry: {count: 1, delay: 5}
792 skip_fail: false
793
794{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400795
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200796
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400797{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200798{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400799
800- description: Set k8s deploy parameters
801 cmd: |
802 {% for k8s_opt, value in config.k8s_deploy.items() %}
803 {% if value|string() %}
804 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
805 {% endif %}
806 {% endfor %}
807 node_name: {{ HOSTNAME_CFG01 }}
808 retry: {count: 1, delay: 1}
809 skip_fail: false
810
811{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400812
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200813
814{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
815{#############################################}
816- description: Set SL docker images deploy parameters
817 cmd: |
818 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
819 {%- for sl_opt, value in config.sl_deploy.items() %}
820 {%- if value|string() %}
821 {%- if OVERRIDES_FILENAME %}
822 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
823 {%- else %}
824 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
825 {%- endif %}
826 {%- endif %}
827 {%- endfor %}
828 salt '*' saltutil.refresh_pillar;
829 sleep 10
830 node_name: {{ HOSTNAME_CFG01 }}
831 retry: {count: 1, delay: 1}
832 skip_fail: false
833{%- endmacro %}
834
835
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400836{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200837{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400838
839{% for ssh in config.underlay.ssh %}
840{% if ssh["node_name"].startswith("cmp") %}
841{% set node_hostname = ssh["node_name"].split('.')[0] %}
842- description: Register compute {{ ssh['node_name'] }}
843 cmd: |
844 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
845 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
846 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400847 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400848 export config_host={{ config.salt.salt_master_host }}
849 export node_domain={{ DOMAIN_NAME }}
850 export nodes_os="xenial"
851 export node_hostname={{ node_hostname }}
852 set -xe
853 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
854 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
855 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
856 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
857
858 # Add wrapper to apt-get to avoid race conditions
859 # with cron jobs running 'unattended-upgrades' script
860 aptget_wrapper() {
861 local apt_wrapper_timeout=300
862 local start_time=$(date '+%s')
863 local fin_time=$((start_time + apt_wrapper_timeout))
864 while true; do
865 if (( "$(date '+%s')" > fin_time )); then
866 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
867 fi
868 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
869 echo "Waiting while another apt/dpkg process releases locks ..."
870 sleep 30
871 continue
872 else
873 apt-get $@
874 break
875 fi
876 done
877 }
878
879 # Set default salt version
880 if [ -z "$saltversion" ]; then
881 saltversion="2016.3"
882 fi
883 echo "Using Salt version $saltversion"
884
885 echo "Preparing base OS ..."
886
887 case "$node_os" in
888 trusty)
889 # workaround for old cloud-init only configuring the first iface
890 iface_config_dir="/etc/network/interfaces"
891 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
892
893 for iface in $ifaces; do
894 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
895 done
896
897 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
898
899 # SUGGESTED UPDATE:
900 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
901 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
902 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
903 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
904 #install_salt_minion_pkg
905
906 # DEPRECATED:
907 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
908 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
909
910 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
911 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
912
913 aptget_wrapper clean
914 aptget_wrapper update
915 aptget_wrapper install -y salt-common
916 aptget_wrapper install -y salt-minion
917 ;;
918 xenial)
919
920 # workaround for new cloud-init setting all interfaces statically
921 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
922
923 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
924
925 # SUGGESTED UPDATE:
926 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
927 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
928 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
929 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
930 #install_salt_minion_pkg
931
932 # DEPRECATED:
933 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
934 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
935
936 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
937 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
938
939 aptget_wrapper clean
940 aptget_wrapper update
941 aptget_wrapper install -y salt-minion
942 ;;
943 rhel|centos|centos7|centos7|rhel6|rhel7)
944 yum install -y git
945 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
946 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
947 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
948 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
949 install_salt_minion_pkg
950 ;;
951 *)
952 msg="OS '$node_os' is not supported."
953 esac
954
955 echo "Configuring Salt minion ..."
956 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
957 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
958
959 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
960
961 sleep 1
962
963 echo "Classifying node ..."
964 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
965 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
966 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
967 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
968 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
969 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
970
971 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
972 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
973 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
974 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
975 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
976
977 if [ "$node_network05_iface" != "" ]; then
978 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
979 fi
980
981 # find more parameters (every env starting param_)
982 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
983 if [ "$more_params" != "" ]; then
984 echo "Additional params: $more_params"
985 more_params=", $more_params"
986 fi
987
988 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}}"
989
990 sleep 5
991
992 salt-call saltutil.sync_all
993 salt-call mine.flush
994 salt-call mine.update
995 node_name: {{ ssh['node_name'] }}
996 retry: {count: 1, delay: 1}
997 skip_fail: false
998{%- endif %}
999{%- endfor %}
1000
1001- description: Refresh pillars on all minions
1002 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1003 node_name: {{ HOSTNAME_CFG01 }}
1004 retry: {count: 1, delay: 5}
1005 skip_fail: false
1006
1007- description: Sync all salt resources
1008 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1009 node_name: {{ HOSTNAME_CFG01 }}
1010 retry: {count: 1, delay: 5}
1011 skip_fail: false
1012
sgudz160b7302017-12-22 17:01:10 +02001013{%- endmacro %}