blob: bd7013809091485a5de226d960679e10a2125000 [file] [log] [blame]
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +03001{% from 'virtual-mcp11-k8s-calico/underlay.yaml' import HOSTNAME_CFG01 with context %}
2{% from 'virtual-mcp11-k8s-calico/underlay.yaml' import REPOSITORY_SUITE with context %}
3
4{% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab') %}
Valentyn Yakovlev08acf9f2017-06-07 14:02:36 +03005{% set SALT_MODELS_BRANCH = os_env('SALT_MODELS_BRANCH','master') %}
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +03006{% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %}
7
8# Address pools for reclass cluster model are taken in the following order:
9# 1. environment variables,
10# 2. config.underlay.address_pools based on fuel-devops address pools
11# (see generated '.ini' file after underlay is created),
12# 3. defaults
13{% set address_pools = config.underlay.address_pools %}
14{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '172.16.10.0/24')) %}
15{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '192.168.10.0/24')) %}
16
17{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
18{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020019
vrovachevaf553ba2017-05-26 15:26:18 +040020# Set docker engine version if one exported as environment variables
21{% set DOCKER_ENGINE = os_env('DOCKER_ENGINE', "") %}
22{% set LAB_CONFIG_NAME = os_env('LAB_CONFIG_NAME', "virtual-mcp11-k8s-calico") %}
23
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020024# Install salt to the config node
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020025- description: Installing salt master on cfg01
26 cmd: apt-get install -y reclass git; apt-get install -y salt-master
27 node_name: {{ HOSTNAME_CFG01 }}
28 retry: {count: 1, delay: 1}
29 skip_fail: false
30
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020031- description: Configure salt-master on cfg01
32 cmd: |
33 cat << 'EOF' >> /etc/salt/master.d/master.conf
34 file_roots:
35 base:
36 - /usr/share/salt-formulas/env
37 pillar_opts: False
38 open_mode: True
39 reclass: &reclass
40 storage_type: yaml_fs
41 inventory_base_uri: /srv/salt/reclass
42 ext_pillar:
43 - reclass: *reclass
44 master_tops:
45 reclass: *reclass
46 EOF
47 node_name: {{ HOSTNAME_CFG01 }}
48 retry: {count: 1, delay: 1}
49 skip_fail: false
50
51- description: Configure GIT settings and certificates
52 cmd: touch /root/.git_trusted_certs.pem;
Matthew Mosesohnd0632b82017-05-30 17:51:30 +030053 for server in github.com; do
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020054 openssl s_client -showcerts -connect $server:443 </dev/null
55 | openssl x509 -outform PEM
56 >> /root/.git_trusted_certs.pem;
57 done;
58 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
59 HOME=/root git config --global user.email "tcp-qa@example.com";
60 HOME=/root git config --global user.name "TCP QA";
61 node_name: {{ HOSTNAME_CFG01 }}
62 retry: {count: 1, delay: 1}
63 skip_fail: false
64
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020065- description: Clone reclass models with submodules
Tatyana Leontovichcf37cb22017-05-19 14:59:38 +030066 cmd: |
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020067 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Valentyn Yakovlev08acf9f2017-06-07 14:02:36 +030068 git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
69 pushd /srv/salt/reclass && git checkout {{ SALT_MODELS_COMMIT }} && popd;
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020070 mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030071
72 # Replace firstly to an intermediate value to avoid intersection between
73 # already replaced and replacing networks.
74 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
75 # 192.168.10 -> 10.16.0 (generated network for admin)
76 # 10.16.0 -> <external network>
77 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Tatyana Leontovich573584a2017-05-19 14:54:00 +030078 find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
79 find /srv/salt/reclass/ -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030080
81 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
82 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
83
84 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
85
86 # Disable checkouting the model from remote repository
87 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
88 # local storage
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +020089 reclass:
90 storage:
91 data_source:
92 engine: local
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030093 EOF
Tatyana Leontovichcf37cb22017-05-19 14:59:38 +030094
95 # Show the changes to the console
96 cd /srv/salt/reclass/; git diff
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020097 node_name: {{ HOSTNAME_CFG01 }}
98 retry: {count: 1, delay: 1}
99 skip_fail: false
100
Tatyana Leontovichcf37cb22017-05-19 14:59:38 +0300101
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200102- description: Configure reclass
103 cmd: |
104 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Tatyana Leontovich5fbd0382017-05-19 19:41:24 +0300105 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200106 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
107 which wget > /dev/null || (apt-get update; apt-get install -y wget);
108 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
109 wget -O - "${FORMULA_GPG}" | apt-key add -;
110 apt-get clean; apt-get update;
111 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich644446f2017-06-08 13:43:36 +0300112 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch");
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200113 echo -e "\nInstalling all required salt formulas\n";
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300114 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200115 for formula_service in "${formula_services[@]}"; do
116 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
117 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
118 done;
119 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
120 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
121 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
122
123 cat << 'EOF' >> /etc/reclass/reclass-config.yml
124 storage_type: yaml_fs
125 pretty_print: True
126 output: yaml
127 inventory_base_uri: /srv/salt/reclass
128 EOF
129 node_name: {{ HOSTNAME_CFG01 }}
130 retry: {count: 1, delay: 1}
131 skip_fail: false
132
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300133- description: Restart salt-master service
134 cmd: |
135 systemctl restart salt-master;
136 node_name: {{ HOSTNAME_CFG01 }}
137 retry: {count: 1, delay: 5}
138 skip_fail: false
139
140{% for ssh in config.underlay.ssh %}
141- description: Configure salt-minion on {{ ssh['node_name'] }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200142 cmd: |
143 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
144 cat << "EOF" >> /etc/salt/minion.d/minion.conf
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300145 id: {{ ssh['node_name'] }}
146 master: {{ config.salt.salt_master_host }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200147 EOF
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300148 eatmydata apt-get install -y salt-minion;
149 echo "Check for system info and metadata availability ...";
150 salt-call --no-color grains.items;
151 salt-call --no-color pillar.items;
152 node_name: {{ ssh['node_name'] }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200153 retry: {count: 1, delay: 1}
154 skip_fail: false
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300155{% endfor %}
156
157- description: Accept salt keys from all the nodes
158 cmd: salt-key -A -y
159 node_name: {{ HOSTNAME_CFG01 }}
160 retry: {count: 1, delay: 5}
161 skip_fail: true
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200162
163- description: Configure salt adoptors on cfg01
164 cmd: |
165 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
166 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
167 node_name: {{ HOSTNAME_CFG01 }}
168 retry: {count: 1, delay: 1}
169 skip_fail: false
170
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200171# Prepare salt services and nodes settings
172- description: Run 'linux' formula on cfg01
173 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
174 -C 'I@salt:master' state.sls linux;
175 node_name: {{ HOSTNAME_CFG01 }}
176 retry: {count: 1, delay: 5}
177 skip_fail: false
178
179- description: Run 'openssh' formula on cfg01
180 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
181 -C 'I@salt:master' state.sls openssh;
182 salt --hard-crash --state-output=mixed --state-verbose=False
183 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
184 yes/' /etc/ssh/sshd_config && service ssh restart";
185 node_name: {{ HOSTNAME_CFG01 }}
186 retry: {count: 3, delay: 5}
187 skip_fail: false
188
189- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
190 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
191 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
192 node_name: {{ HOSTNAME_CFG01 }}
193 retry: {count: 1, delay: 1}
194 skip_fail: false
195
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300196- description: Run 'salt.master' formula on cfg01
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200197 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
198 -C 'I@salt:master' state.sls salt.master.service;
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200199 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300200 retry: {count: 2, delay: 5}
201 skip_fail: false
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200202
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300203- description: Run 'salt' formula on cfg01 with workaround proposed in PROD-10894
204 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
205 -C 'I@salt:master' state.sls salt;
206 salt --hard-crash --state-output=mixed --state-verbose=False
207 -C 'I@salt:master' saltutil.sync_all
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200208 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300209 retry: {count: 5, delay: 5}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200210 skip_fail: false
211
212- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
213 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
214 -C 'I@salt:master' state.sls reclass
215 node_name: {{ HOSTNAME_CFG01 }}
216 retry: {count: 1, delay: 5}
217 skip_fail: false
218
219- description: Refresh pillars on all minions
220 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
221 node_name: {{ HOSTNAME_CFG01 }}
222 retry: {count: 1, delay: 5}
223 skip_fail: false
224
225- description: Sync all salt resources
226 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
227 node_name: {{ HOSTNAME_CFG01 }}
228 retry: {count: 1, delay: 5}
229 skip_fail: false
230
Sergii Golovatiuk5b659d42017-05-26 17:38:06 +0200231- description: Show reclass-salt --top
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300232 cmd: reclass-salt --top
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200233 node_name: {{ HOSTNAME_CFG01 }}
234 retry: {count: 1, delay: 5}
235 skip_fail: false
236
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300237- description: Execute salt.minion.cert
238 cmd: salt-call --no-color state.sls salt.minion.cert -l info;
239 node_name: {{ HOSTNAME_CFG01 }}
240 retry: {count: 1, delay: 5}
241 skip_fail: false
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200242
vrovachevaf553ba2017-05-26 15:26:18 +0400243# Change environment configuration before deploy
244
245{% for image_prefix in "CALICOCTL CALICO CALICO_CNI HYPERKUBE NETCHECKER_AGENT NETCHECKER_SERVER".split() %}
246- description: Change {{ image_prefix.lower() }} image to custom if necessary
247 cmd: |
248 image_link={{ os_env('CUSTOM_IMAGE_' + image_prefix, "") }}
249 if [ -n "${image_link}" ]; then
250 echo "{{ image_prefix.lower() }} image link changed to "${image_link}""
251 salt -C 'I@salt:master' reclass.cluster_meta_set kubernetes_{{ image_prefix.lower() }}_image ${image_link}
252 else
253 echo "Custom {{ image_prefix.lower() }} image link is not set, skipped."
254 fi
255 node_name: {{ HOSTNAME_CFG01 }}
256 retry: {count: 1, delay: 5}
257 skip_fail: false
258{% endfor %}
259
260- description: Change docker engine version to custom if necessary
261 cmd: |
262 FILE="/srv/salt/reclass/classes/cluster/{{ LAB_CONFIG_NAME }}/kubernetes/compute.yml"
263 if [ -n "{{ DOCKER_ENGINE }}" ]; then
264 echo "Change docker engine version to: {{ DOCKER_ENGINE }}"
265 sed "s#docker-engine=.*#docker-engine={{ DOCKER_ENGINE }}#" -i.bak ${FILE}
266 else
267 echo "Custom docker engine version is not set, skipped."
268 fi
269 node_name: {{ HOSTNAME_CFG01 }}
270 retry: {count: 1, delay: 5}
271 skip_fail: false
272
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200273# Bootstrap all nodes
274
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300275- description: Configure linux on other nodes
276 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +0300277 cfg01* and not mon*' state.sls linux
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200278 node_name: {{ HOSTNAME_CFG01 }}
279 retry: {count: 1, delay: 5}
280 skip_fail: false
281
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +0300282- description: Configure linux on mon nodes
283 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'mon*' state.sls linux
284 node_name: {{ HOSTNAME_CFG01 }}
285 retry: {count: 2, delay: 5}
286 skip_fail: false
287
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200288- description: Configure openssh on all nodes
289 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300290 cfg01*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200291 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
292 yes/' /etc/ssh/sshd_config && service ssh restart"
293 node_name: {{ HOSTNAME_CFG01 }}
294 retry: {count: 1, delay: 5}
295 skip_fail: false
296
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300297- description: Configure salt.minion on other nodes
298 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
299 cfg01*' state.sls salt.minion
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200300 node_name: {{ HOSTNAME_CFG01 }}
301 retry: {count: 3, delay: 5}
302 skip_fail: false
303
304- description: Check salt minion versions on slaves
305 cmd: salt '*' test.version
306 node_name: {{ HOSTNAME_CFG01 }}
307 retry: {count: 1, delay: 5}
308 skip_fail: false
309
310- description: Check salt top states on nodes
311 cmd: salt '*' state.show_top
312 node_name: {{ HOSTNAME_CFG01 }}
313 retry: {count: 1, delay: 5}
314 skip_fail: false
315
316- description: Configure ntp and rsyslog on nodes
317 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog
318 node_name: {{ HOSTNAME_CFG01 }}
319 retry: {count: 1, delay: 10}
320 skip_fail: false