blob: bb54f8ec471bfff316af722e2b4c1c10795d4027 [file] [log] [blame]
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +03001{% from 'virtual-mcp-ocata-cicd/underlay.yaml' import HOSTNAME_CFG01 with context %}
2{% from 'virtual-mcp-ocata-cicd/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') %}
5{% set SALT_MODELS_BRANCH = os_env('SALT_MODELS_BRANCH','master') %}
6{% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %}
7
8# 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
9{% set SALT_MODELS_REF_CHANGE = os_env('SALT_MODELS_REF_CHANGE', '') %}
10
11# Address pools for reclass cluster model are taken in the following order:
12# 1. environment variables,
13# 2. config.underlay.address_pools based on fuel-devops address pools
14# (see generated '.ini' file after underlay is created),
15# 3. defaults
16{% set address_pools = config.underlay.address_pools %}
17{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
18{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
19{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
20{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
21
22{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
23{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
24{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
25{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
26
27# Install salt to the config node
28
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030029- description: Installing salt master on cfg01
30 cmd: eatmydata apt-get install -y reclass git salt-master
31 node_name: {{ HOSTNAME_CFG01 }}
32 retry: {count: 1, delay: 1}
33 skip_fail: false
34
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030035- description: Configure salt-master on cfg01
36 cmd: |
37 cat << 'EOF' >> /etc/salt/master.d/master.conf
38 file_roots:
39 base:
40 - /usr/share/salt-formulas/env
41 pillar_opts: False
42 open_mode: True
43 reclass: &reclass
44 storage_type: yaml_fs
45 inventory_base_uri: /srv/salt/reclass
46 ext_pillar:
47 - reclass: *reclass
48 master_tops:
49 reclass: *reclass
50 EOF
51 node_name: {{ HOSTNAME_CFG01 }}
52 retry: {count: 1, delay: 1}
53 skip_fail: false
54
55- description: Configure GIT settings and certificates
56 cmd: touch /root/.git_trusted_certs.pem;
57 for server in git.tcpcloud.eu github.com; do
58 openssl s_client -showcerts -connect $server:443 </dev/null
59 | openssl x509 -outform PEM
60 >> /root/.git_trusted_certs.pem;
61 done;
62 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
63 HOME=/root git config --global user.email "tcp-qa@example.com";
64 HOME=/root git config --global user.name "TCP QA";
65 node_name: {{ HOSTNAME_CFG01 }}
66 retry: {count: 1, delay: 1}
67 skip_fail: false
68
69
70- description: Clone reclass models with submodules
71 cmd: |
72 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
73 git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
74 pushd /srv/salt/reclass && git checkout {{ SALT_MODELS_COMMIT }} && popd;
75 {%- if SALT_MODELS_REF_CHANGE != '' %}
76 pushd /srv/salt/reclass && git fetch {{ SALT_MODELS_REPOSITORY }} {{ SALT_MODELS_REF_CHANGE }} && git checkout FETCH_HEAD && popd;
77 {%- endif %}
78 mkdir -p /srv/salt/reclass/classes/service;
79
80 # Replace firstly to an intermediate value to avoid intersection between
81 # already replaced and replacing networks.
82 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
83 # 192.168.10 -> 10.16.0 (generated network for admin)
84 # 10.16.0 -> <external network>
85 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
86 find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
87 find /srv/salt/reclass/ -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
88 find /srv/salt/reclass/ -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} +
89 find /srv/salt/reclass/ -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
90
91 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
92 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
93 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} +
94 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {} +
95
96 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
97
98 # Disable checkouting the model from remote repository
99 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
100 # local storage
101 reclass:
102 storage:
103 data_source:
104 engine: local
105 EOF
106
107 # Show the changes to the console
108 cd /srv/salt/reclass/; git diff
109 node_name: {{ HOSTNAME_CFG01 }}
110 retry: {count: 1, delay: 1}
111 skip_fail: false
112
113- description: Configure reclass
114 cmd: |
115 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
obutenko89aedf82017-08-04 12:50:37 +0300116 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
117 FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg};
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300118 which wget > /dev/null || (apt-get update; apt-get install -y wget);
119 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
120 wget -O - "${FORMULA_GPG}" | apt-key add -;
121 apt-get clean; apt-get update;
122 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitriev76f65462017-07-20 16:21:26 -0400123 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch" "docker" "kibana");
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300124 echo -e "\nInstalling all required salt formulas\n";
125 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
126 for formula_service in "${formula_services[@]}"; do
127 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
128 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
129 done;
130 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
131 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
132 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
133
134 cat << 'EOF' >> /etc/reclass/reclass-config.yml
135 storage_type: yaml_fs
136 pretty_print: True
137 output: yaml
138 inventory_base_uri: /srv/salt/reclass
139 EOF
140 node_name: {{ HOSTNAME_CFG01 }}
141 retry: {count: 1, delay: 1}
142 skip_fail: false
143
Dennis Dmitriev9c2707e2017-07-21 13:17:53 +0300144- description: "*Workaround* remove all cfg01 nodes except {{ HOSTNAME_CFG01 }} to not depend on other clusters in 'reclass --top'"
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300145 cmd: |
Dennis Dmitriev9c2707e2017-07-21 13:17:53 +0300146 # Remove all other nodes except {{ HOSTNAME_CFG01 }} to not rely on them for 'reclass --top'
147 find /srv/salt/reclass/nodes/ -type f -not -name {{ HOSTNAME_CFG01 }}.yml -delete
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300148 node_name: {{ HOSTNAME_CFG01 }}
149 retry: {count: 1, delay: 5}
150 skip_fail: false
151
152- description: Show reclass-salt --top for cfg01 node
Dennis Dmitriev9c2707e2017-07-21 13:17:53 +0300153 cmd: reclass-salt --top
154 node_name: {{ HOSTNAME_CFG01 }}
155 retry: {count: 1, delay: 5}
156 skip_fail: false
157
158- description: Restart salt-master service
159 cmd: systemctl restart salt-master;
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300160 node_name: {{ HOSTNAME_CFG01 }}
161 retry: {count: 1, delay: 5}
162 skip_fail: false
163
164{%- for ssh in config.underlay.ssh %}
165- description: Configure salt-minion on {{ ssh['node_name'] }}
166 cmd: |
167 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
168 cat << "EOF" >> /etc/salt/minion.d/minion.conf
169 id: {{ ssh['node_name'] }}
170 master: {{ config.salt.salt_master_host }}
171 EOF
172 eatmydata apt-get install -y salt-minion;
173 echo "Check for system info and metadata availability ...";
174 salt-call --no-color grains.items;
175 salt-call --no-color pillar.items;
176 node_name: {{ ssh['node_name'] }}
177 retry: {count: 1, delay: 1}
178 skip_fail: false
179{%- endfor %}
180
181
182- description: Accept salt keys from all the nodes
183 cmd: salt-key -A -y
184 node_name: {{ HOSTNAME_CFG01 }}
185 retry: {count: 1, delay: 5}
186 skip_fail: true
187
188- description: Configure salt adoptors on cfg01
189 cmd: |
190 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
191 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
192 node_name: {{ HOSTNAME_CFG01 }}
193 retry: {count: 1, delay: 1}
194 skip_fail: false
195
196# Prepare salt services and nodes settings
197- description: Run 'linux' formula on cfg01
198 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
199 node_name: {{ HOSTNAME_CFG01 }}
200 retry: {count: 1, delay: 5}
201 skip_fail: false
202
203- description: Run 'openssh' formula on cfg01
204 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
205 -C 'I@salt:master' state.sls openssh;
206 salt --hard-crash --state-output=mixed --state-verbose=False
207 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
208 yes/' /etc/ssh/sshd_config && service ssh reload";
209 node_name: {{ HOSTNAME_CFG01 }}
210 retry: {count: 3, delay: 5}
211 skip_fail: false
212
213- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
214 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
215 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
216 node_name: {{ HOSTNAME_CFG01 }}
217 retry: {count: 1, delay: 1}
218 skip_fail: false
219
220- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve4cfced2017-07-27 07:31:21 +0300221 cmd: timeout 120 salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300222 node_name: {{ HOSTNAME_CFG01 }}
223 retry: {count: 2, delay: 5}
224 skip_fail: false
225
226- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
227 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
228 -C 'I@salt:master' state.sls reclass
229 node_name: {{ HOSTNAME_CFG01 }}
230 retry: {count: 1, delay: 5}
231 skip_fail: false
232
233- description: Refresh pillars on all minions
234 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
235 node_name: {{ HOSTNAME_CFG01 }}
236 retry: {count: 1, delay: 5}
237 skip_fail: false
238
239- description: Show reclass-salt --top for all generated nodes
240 cmd: reclass-salt --top
241 node_name: {{ HOSTNAME_CFG01 }}
242 retry: {count: 1, delay: 5}
243 skip_fail: false
244
245- description: Sync all salt resources
246 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
247 node_name: {{ HOSTNAME_CFG01 }}
248 retry: {count: 1, delay: 5}
249 skip_fail: false
250
251- description: Configure linux on master
252 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
253 node_name: {{ HOSTNAME_CFG01 }}
254 retry: {count: 1, delay: 5}
255 skip_fail: false
256
Dennis Dmitrievf8546172017-07-20 21:57:05 +0300257- description: Configure salt.minion on master
Dennis Dmitriev980db162017-07-27 09:40:01 +0300258 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitrievf8546172017-07-20 21:57:05 +0300259 -C 'I@salt:master' state.sls salt.minion
260 node_name: {{ HOSTNAME_CFG01 }}
261 retry: {count: 3, delay: 10}
262 skip_fail: false
263
264- description: Run state 'salt' on master (for salt.api, etc)
265 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
266 -C 'I@salt:master' state.sls salt
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300267 node_name: {{ HOSTNAME_CFG01 }}
268 retry: {count: 3, delay: 10}
269 skip_fail: false
270
271# Bootstrap all nodes
272
273- description: Configure linux on other nodes
274 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls 'linux'
275 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve4cfced2017-07-27 07:31:21 +0300276 retry: {count: 3, delay: 5}
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300277 skip_fail: false
278
279- description: Configure openssh on all nodes
280 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls openssh;
281 salt --hard-crash --state-output=mixed --state-verbose=False
282 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
283 yes/' /etc/ssh/sshd_config && service ssh reload"
284 node_name: {{ HOSTNAME_CFG01 }}
285 retry: {count: 1, delay: 5}
286 skip_fail: false
287
288- description: Configure salt.minion on other nodes
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300289 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion && sleep 10
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300290 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev5b0e5f32017-07-22 11:30:26 +0300291 retry: {count: 3, delay: 15}
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300292 skip_fail: false
293
294- description: Check salt minion versions on slaves
295 cmd: salt '*' test.version
296 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300297 retry: {count: 2, delay: 5}
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300298 skip_fail: false
299
300- description: Check salt top states on nodes
301 cmd: salt '*' state.show_top
302 node_name: {{ HOSTNAME_CFG01 }}
303 retry: {count: 1, delay: 5}
304 skip_fail: false
305
306- description: Configure ntp and rsyslog on nodes
307 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
308 node_name: {{ HOSTNAME_CFG01 }}
309 retry: {count: 1, delay: 10}
310 skip_fail: false
311
312#- description: Hack gtw node
313# cmd: salt 'gtw*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4";
314# node_name: {{ HOSTNAME_CFG01 }}
315# retry: {count: 1, delay: 10}
316# skip_fail: false
317
318#- description: Hack cmp01 node
319# cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
320# node_name: {{ HOSTNAME_CFG01 }}
321# retry: {count: 1, delay: 10}
322# skip_fail: false
323
324#- description: Hack cmp02 node
325# cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
326# node_name: {{ HOSTNAME_CFG01 }}
327# retry: {count: 1, delay: 10}
328# skip_fail: false