blob: fa19cb6193294d3277230669b52d876aa7125038 [file] [log] [blame]
Dennis Dmitrievab83ea42017-05-12 16:52:45 +03001{% from 'virtual-mcp11-ovs/underlay.yaml' import HOSTNAME_CFG01 with context %}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +03002{% from 'virtual-mcp11-ovs/underlay.yaml' import REPOSITORY_SUITE with context %}
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +03003
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') %}
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +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', '192.168.10.0/24')) %}
15{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
16{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
17{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
18
19{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
20{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
21{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
22{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030023
24# Install salt to the config node
25
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030026#- description: (moved to cloud-init config) Configure repository on the cfg01 node
27# cmd:
28# echo "172.18.248.114 jenkins.mcp.mirantis.net gerrit.mcp.mirantis.net" >> /etc/hosts;
29# echo "185.135.196.10 apt-mk.mirantis.com" >> /etc/hosts;
30# echo "nameserver 172.18.208.44 >> /etc/resolv.conf;
31# echo "nameserver 8.8.8.8 >> /etc/resolv.conf;
32# which wget >/dev/null || (apt-get update; apt-get install -y wget);
33# echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial nightly salt extra" > /etc/apt/sources.list.d/mcp_salt.list;
34# wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -;
35# echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list;
36# wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -;
37# node_name: {{ HOSTNAME_CFG01 }}
38# retry: {count: 1, delay: 1}
39# skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030040
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030041#- description: Update packages on cfg01
42# cmd: apt-get clean; eatmydata apt-get update
43# node_name: {{ HOSTNAME_CFG01 }}
44# retry: {count: 1, delay: 1}
45# skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030046
47- description: Installing salt master on cfg01
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030048 cmd: eatmydata apt-get install -y reclass git salt-master
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030049 node_name: {{ HOSTNAME_CFG01 }}
50 retry: {count: 1, delay: 1}
51 skip_fail: false
52
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030053#- description: (moved to cloud-init config) Install common packages on cfg01
54# cmd: eatmydata apt-get install -y python-pip wget curl tmux byobu iputils-ping traceroute htop tree
55# node_name: {{ HOSTNAME_CFG01 }}
56# retry: {count: 1, delay: 1}
57# skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030058
59- description: Configure salt-master on cfg01
60 cmd: |
61 cat << 'EOF' >> /etc/salt/master.d/master.conf
62 file_roots:
63 base:
64 - /usr/share/salt-formulas/env
65 pillar_opts: False
66 open_mode: True
67 reclass: &reclass
68 storage_type: yaml_fs
69 inventory_base_uri: /srv/salt/reclass
70 ext_pillar:
71 - reclass: *reclass
72 master_tops:
73 reclass: *reclass
74 EOF
75 node_name: {{ HOSTNAME_CFG01 }}
76 retry: {count: 1, delay: 1}
77 skip_fail: false
78
79- description: Configure GIT settings and certificates
80 cmd: touch /root/.git_trusted_certs.pem;
Matthew Mosesohnd0632b82017-05-30 17:51:30 +030081 for server in github.com; do
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030082 openssl s_client -showcerts -connect $server:443 </dev/null
83 | openssl x509 -outform PEM
84 >> /root/.git_trusted_certs.pem;
85 done;
86 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
87 HOME=/root git config --global user.email "tcp-qa@example.com";
88 HOME=/root git config --global user.name "TCP QA";
89 node_name: {{ HOSTNAME_CFG01 }}
90 retry: {count: 1, delay: 1}
91 skip_fail: false
92
93
94- description: Clone reclass models with submodules
95 cmd: |
96 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Valentyn Yakovlev08acf9f2017-06-07 14:02:36 +030097 git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
98 pushd /srv/salt/reclass && git checkout {{ SALT_MODELS_COMMIT }} && popd;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030099
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300100 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300101
102 # Replace firstly to an intermediate value to avoid intersection between
103 # already replaced and replacing networks.
104 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
105 # 192.168.10 -> 10.16.0 (generated network for admin)
106 # 10.16.0 -> <external network>
107 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
108 find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
109 find /srv/salt/reclass/ -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
110 find /srv/salt/reclass/ -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} +
111 find /srv/salt/reclass/ -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
112
113 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
114 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
115 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} +
116 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {} +
117
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300118 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
119
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300120 # Disable checkouting the model from remote repository
121 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
122 # local storage
123 reclass:
124 storage:
125 data_source:
126 engine: local
127 EOF
128
129 # Show the changes to the console
130 cd /srv/salt/reclass/; git diff
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300131 node_name: {{ HOSTNAME_CFG01 }}
132 retry: {count: 1, delay: 1}
133 skip_fail: false
134
135- description: Configure reclass
136 cmd: |
137 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Tatyana Leontovicheed70d72017-05-25 16:32:17 +0300138 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
Tatyana Leontovich3c6aa452017-04-25 15:04:40 +0300139 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300140 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Tatyana Leontovich543afa92017-04-21 14:48:03 +0300141 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300142 wget -O - "${FORMULA_GPG}" | apt-key add -;
143 apt-get clean; apt-get update;
144 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich644446f2017-06-08 13:43:36 +0300145 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch");
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300146 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300147 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300148 for formula_service in "${formula_services[@]}"; do
149 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
150 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
151 done;
152 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
153 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
154 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
155
156 cat << 'EOF' >> /etc/reclass/reclass-config.yml
157 storage_type: yaml_fs
158 pretty_print: True
159 output: yaml
160 inventory_base_uri: /srv/salt/reclass
161 EOF
162 node_name: {{ HOSTNAME_CFG01 }}
163 retry: {count: 1, delay: 1}
164 skip_fail: false
165
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300166- description: Restart salt-master service
167 cmd: |
168 systemctl restart salt-master;
169 node_name: {{ HOSTNAME_CFG01 }}
170 retry: {count: 1, delay: 5}
171 skip_fail: false
172
173{% for ssh in config.underlay.ssh %}
174- description: Configure salt-minion on {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300175 cmd: |
176 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
177 cat << "EOF" >> /etc/salt/minion.d/minion.conf
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300178 id: {{ ssh['node_name'] }}
179 master: {{ config.salt.salt_master_host }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300180 EOF
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300181 eatmydata apt-get install -y salt-minion;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300182 echo "Check for system info and metadata availability ...";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300183 salt-call --no-color grains.items;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300184 salt-call --no-color pillar.items;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300185 node_name: {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300186 retry: {count: 1, delay: 1}
187 skip_fail: false
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300188{% endfor %}
189
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300190
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300191- description: Accept salt keys from all the nodes
192 cmd: salt-key -A -y
193 node_name: {{ HOSTNAME_CFG01 }}
194 retry: {count: 1, delay: 5}
195 skip_fail: true
196
197
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300198- description: Configure salt adoptors on cfg01
199 cmd: |
200 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
201 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
202 node_name: {{ HOSTNAME_CFG01 }}
203 retry: {count: 1, delay: 1}
204 skip_fail: false
205
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300206
207# Prepare salt services and nodes settings
208- description: Run 'linux' formula on cfg01
209 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
210 -C 'I@salt:master' state.sls linux;
211 node_name: {{ HOSTNAME_CFG01 }}
212 retry: {count: 1, delay: 5}
213 skip_fail: false
214
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300215
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300216- description: Run 'openssh' formula on cfg01
217 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
218 -C 'I@salt:master' state.sls openssh;
219 salt --hard-crash --state-output=mixed --state-verbose=False
220 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
221 yes/' /etc/ssh/sshd_config && service ssh restart";
222 node_name: {{ HOSTNAME_CFG01 }}
223 retry: {count: 3, delay: 5}
224 skip_fail: false
225
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300226
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300227- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
228 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
229 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
230 node_name: {{ HOSTNAME_CFG01 }}
231 retry: {count: 1, delay: 1}
232 skip_fail: false
233
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300234- description: Run 'salt.master' formula on cfg01
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300235 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
236 -C 'I@salt:master' state.sls salt.master.service;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300237 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300238 retry: {count: 2, delay: 5}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300239 skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300240
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300241- description: Run 'salt' formula on cfg01 with workaround proposed in PROD-10894
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300242 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
243 -C 'I@salt:master' state.sls salt;
244 salt --hard-crash --state-output=mixed --state-verbose=False
245 -C 'I@salt:master' saltutil.sync_all
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300246 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300247 retry: {count: 5, delay: 5}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300248 skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300249
250- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
251 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
252 -C 'I@salt:master' state.sls reclass
253 node_name: {{ HOSTNAME_CFG01 }}
254 retry: {count: 1, delay: 5}
255 skip_fail: false
256
257- description: Refresh pillars on all minions
258 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
259 node_name: {{ HOSTNAME_CFG01 }}
260 retry: {count: 1, delay: 5}
261 skip_fail: false
262
263- description: Sync all salt resources
264 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
265 node_name: {{ HOSTNAME_CFG01 }}
266 retry: {count: 1, delay: 5}
267 skip_fail: false
268
269- description: Show reclass-salt --top
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300270 cmd: reclass-salt --top
271 node_name: {{ HOSTNAME_CFG01 }}
272 retry: {count: 1, delay: 5}
273 skip_fail: false
274
275- description: Execute salt.minion.cert
276 cmd: salt-call --no-color state.sls salt.minion.cert -l info;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300277 node_name: {{ HOSTNAME_CFG01 }}
278 retry: {count: 1, delay: 5}
279 skip_fail: false
280
281
282# Bootstrap all nodes
283
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300284- description: Configure linux on other nodes
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300285 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300286 cfg01*' state.sls linux
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300287 node_name: {{ HOSTNAME_CFG01 }}
288 retry: {count: 1, delay: 5}
289 skip_fail: false
290
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300291- description: Configure openssh on all nodes
292 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300293 cfg01*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300294 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
295 yes/' /etc/ssh/sshd_config && service ssh restart"
296 node_name: {{ HOSTNAME_CFG01 }}
297 retry: {count: 1, delay: 5}
298 skip_fail: false
299
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300300- description: Configure salt.minion on other nodes
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300301 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300302 cfg01*' state.sls salt.minion
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300303 node_name: {{ HOSTNAME_CFG01 }}
304 retry: {count: 3, delay: 5}
305 skip_fail: false
306
307- description: Check salt minion versions on slaves
308 cmd: salt '*' test.version
309 node_name: {{ HOSTNAME_CFG01 }}
310 retry: {count: 1, delay: 5}
311 skip_fail: false
312
313- description: Check salt top states on nodes
314 cmd: salt '*' state.show_top
315 node_name: {{ HOSTNAME_CFG01 }}
316 retry: {count: 1, delay: 5}
317 skip_fail: false
318
319- description: Configure ntp and rsyslog on nodes
320 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog
321 node_name: {{ HOSTNAME_CFG01 }}
322 retry: {count: 1, delay: 10}
323 skip_fail: false
324
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300325- description: Hack gtw node
326 cmd: salt 'gtw*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4";
327 node_name: {{ HOSTNAME_CFG01 }}
328 retry: {count: 1, delay: 10}
329 skip_fail: false
330
331- description: Hack cmp01 node
332 cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
333 node_name: {{ HOSTNAME_CFG01 }}
334 retry: {count: 1, delay: 10}
335 skip_fail: false
336
337- description: Hack cmp02 node
338 cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
339 node_name: {{ HOSTNAME_CFG01 }}
340 retry: {count: 1, delay: 10}
341 skip_fail: false