blob: 039338d1462fac229c1807c3ce73e7cef9921904 [file] [log] [blame]
Dennis Dmitrievab83ea42017-05-12 16:52:45 +03001{% from 'virtual-mcp11-ovs-dpdk/underlay.yaml' import HOSTNAME_CFG01 with context %}
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +03002
3{% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab') %}
4{% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %}
5
6# Address pools for reclass cluster model are taken in the following order:
7# 1. environment variables,
8# 2. config.underlay.address_pools based on fuel-devops address pools
9# (see generated '.ini' file after underlay is created),
10# 3. defaults
11{% set address_pools = config.underlay.address_pools %}
12{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
13{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
14{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
15{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.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]) %}
19{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
20{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030021
22# Install salt to the config node
23
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030024#- description: (moved to cloud-init config) Configure repository on the cfg01 node
25# cmd:
26# echo "172.18.248.114 jenkins.mcp.mirantis.net gerrit.mcp.mirantis.net" >> /etc/hosts;
27# echo "185.135.196.10 apt-mk.mirantis.com" >> /etc/hosts;
28# echo "nameserver 172.18.208.44 >> /etc/resolv.conf;
29# echo "nameserver 8.8.8.8 >> /etc/resolv.conf;
30# which wget >/dev/null || (apt-get update; apt-get install -y wget);
31# echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial nightly salt extra" > /etc/apt/sources.list.d/mcp_salt.list;
32# wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -;
33# echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list;
34# wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -;
35# node_name: {{ HOSTNAME_CFG01 }}
36# retry: {count: 1, delay: 1}
37# skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030038
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030039#- description: Update packages on cfg01
40# cmd: apt-get clean; eatmydata apt-get update
41# node_name: {{ HOSTNAME_CFG01 }}
42# retry: {count: 1, delay: 1}
43# skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030044
45- description: Installing salt master on cfg01
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030046 cmd: eatmydata apt-get install -y reclass git salt-master
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030047 node_name: {{ HOSTNAME_CFG01 }}
48 retry: {count: 1, delay: 1}
49 skip_fail: false
50
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030051#- description: (moved to cloud-init config) Install common packages on cfg01
52# cmd: eatmydata apt-get install -y python-pip wget curl tmux byobu iputils-ping traceroute htop tree
53# node_name: {{ HOSTNAME_CFG01 }}
54# retry: {count: 1, delay: 1}
55# skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030056
57- description: Configure salt-master on cfg01
58 cmd: |
59 cat << 'EOF' >> /etc/salt/master.d/master.conf
60 file_roots:
61 base:
62 - /usr/share/salt-formulas/env
63 pillar_opts: False
64 open_mode: True
65 reclass: &reclass
66 storage_type: yaml_fs
67 inventory_base_uri: /srv/salt/reclass
68 ext_pillar:
69 - reclass: *reclass
70 master_tops:
71 reclass: *reclass
72 EOF
73 node_name: {{ HOSTNAME_CFG01 }}
74 retry: {count: 1, delay: 1}
75 skip_fail: false
76
77- description: Configure GIT settings and certificates
78 cmd: touch /root/.git_trusted_certs.pem;
79 for server in git.tcpcloud.eu github.com; do
80 openssl s_client -showcerts -connect $server:443 </dev/null
81 | openssl x509 -outform PEM
82 >> /root/.git_trusted_certs.pem;
83 done;
84 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
85 HOME=/root git config --global user.email "tcp-qa@example.com";
86 HOME=/root git config --global user.name "TCP QA";
87 node_name: {{ HOSTNAME_CFG01 }}
88 retry: {count: 1, delay: 1}
89 skip_fail: false
90
91
92- description: Clone reclass models with submodules
93 cmd: |
94 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030095 git clone -b {{ SALT_MODELS_COMMIT }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
96
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030097 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030098
99 # Replace firstly to an intermediate value to avoid intersection between
100 # already replaced and replacing networks.
101 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
102 # 192.168.10 -> 10.16.0 (generated network for admin)
103 # 10.16.0 -> <external network>
104 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
105 find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
106 find /srv/salt/reclass/ -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
107 find /srv/salt/reclass/ -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} +
108 find /srv/salt/reclass/ -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
109
110 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
111 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
112 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} +
113 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {} +
114
115 # Disable checkouting the model from remote repository
116 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
117 # local storage
118 reclass:
119 storage:
120 data_source:
121 engine: local
122 EOF
123
124 # Show the changes to the console
125 cd /srv/salt/reclass/; git diff
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300126 node_name: {{ HOSTNAME_CFG01 }}
127 retry: {count: 1, delay: 1}
128 skip_fail: false
129
130- description: Configure reclass
131 cmd: |
132 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Tatyana Leontovich543afa92017-04-21 14:48:03 +0300133 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial stable salt};
Tatyana Leontovich3c6aa452017-04-25 15:04:40 +0300134 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300135 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Tatyana Leontovich543afa92017-04-21 14:48:03 +0300136 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300137 wget -O - "${FORMULA_GPG}" | apt-key add -;
138 apt-get clean; apt-get update;
139 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
140 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon");
141 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300142 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300143 for formula_service in "${formula_services[@]}"; do
144 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
145 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
146 done;
147 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
148 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
149 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
150
151 cat << 'EOF' >> /etc/reclass/reclass-config.yml
152 storage_type: yaml_fs
153 pretty_print: True
154 output: yaml
155 inventory_base_uri: /srv/salt/reclass
156 EOF
157 node_name: {{ HOSTNAME_CFG01 }}
158 retry: {count: 1, delay: 1}
159 skip_fail: false
160
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300161- description: Restart salt-master service
162 cmd: |
163 systemctl restart salt-master;
164 node_name: {{ HOSTNAME_CFG01 }}
165 retry: {count: 1, delay: 5}
166 skip_fail: false
167
168{% for ssh in config.underlay.ssh %}
169- description: Configure salt-minion on {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300170 cmd: |
171 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
172 cat << "EOF" >> /etc/salt/minion.d/minion.conf
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300173 id: {{ ssh['node_name'] }}
174 master: {{ config.salt.salt_master_host }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300175 EOF
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300176 eatmydata apt-get install -y salt-minion;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300177 echo "Check for system info and metadata availability ...";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300178 salt-call --no-color grains.items;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300179 salt-call --no-color pillar.items;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300180 node_name: {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300181 retry: {count: 1, delay: 1}
182 skip_fail: false
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300183{% endfor %}
184
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300185
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300186- description: Accept salt keys from all the nodes
187 cmd: salt-key -A -y
188 node_name: {{ HOSTNAME_CFG01 }}
189 retry: {count: 1, delay: 5}
190 skip_fail: true
191
192
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300193- description: Configure salt adoptors on cfg01
194 cmd: |
195 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
196 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
197 node_name: {{ HOSTNAME_CFG01 }}
198 retry: {count: 1, delay: 1}
199 skip_fail: false
200
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300201
202# Prepare salt services and nodes settings
203- description: Run 'linux' formula on cfg01
204 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
205 -C 'I@salt:master' state.sls linux;
206 node_name: {{ HOSTNAME_CFG01 }}
207 retry: {count: 1, delay: 5}
208 skip_fail: false
209
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300210
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300211- description: Run 'openssh' formula on cfg01
212 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
213 -C 'I@salt:master' state.sls openssh;
214 salt --hard-crash --state-output=mixed --state-verbose=False
215 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
216 yes/' /etc/ssh/sshd_config && service ssh restart";
217 node_name: {{ HOSTNAME_CFG01 }}
218 retry: {count: 3, delay: 5}
219 skip_fail: false
220
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300221
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300222- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
223 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
224 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
225 node_name: {{ HOSTNAME_CFG01 }}
226 retry: {count: 1, delay: 1}
227 skip_fail: false
228
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300229#- description: (duplicate of the next two steps) Run 'reclass' formula on cfg01
230# cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
231# -C 'I@salt:master' state.sls reclass;
232# salt-call --hard-crash --state-output=mixed --state-verbose=False state.sls salt.master;
233# node_name: {{ HOSTNAME_CFG01 }}
234# retry: {count: 1, delay: 5}
235# skip_fail: true
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300236
237
238- description: Run 'salt' formula on cfg01
239 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
240 -C 'I@salt:master' state.sls salt.master.service;
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300241 salt-call --hard-crash --state-output=mixed --state-verbose=False
242 state.sls salt.master,salt.api,salt.minion.ca;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300243 systemctl restart salt-minion;
244 node_name: {{ HOSTNAME_CFG01 }}
245 retry: {count: 1, delay: 5}
246 skip_fail: true
247
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300248
249- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
250 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
251 -C 'I@salt:master' state.sls reclass
252 node_name: {{ HOSTNAME_CFG01 }}
253 retry: {count: 1, delay: 5}
254 skip_fail: false
255
256- description: Refresh pillars on all minions
257 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
258 node_name: {{ HOSTNAME_CFG01 }}
259 retry: {count: 1, delay: 5}
260 skip_fail: false
261
262- description: Sync all salt resources
263 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
264 node_name: {{ HOSTNAME_CFG01 }}
265 retry: {count: 1, delay: 5}
266 skip_fail: false
267
268- description: Show reclass-salt --top
269 cmd: reclass-salt --top; salt-call --no-color state.sls salt.minion.cert -l info;
270 node_name: {{ HOSTNAME_CFG01 }}
271 retry: {count: 1, delay: 5}
272 skip_fail: false
273
274
275# Bootstrap all nodes
276
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300277- description: Configure linux on other nodes
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300278 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300279 cfg01*' state.sls linux
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300280 node_name: {{ HOSTNAME_CFG01 }}
281 retry: {count: 1, delay: 5}
282 skip_fail: false
283
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300284- description: Configure openssh on all nodes
285 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300286 cfg01*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300287 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
288 yes/' /etc/ssh/sshd_config && service ssh restart"
289 node_name: {{ HOSTNAME_CFG01 }}
290 retry: {count: 1, delay: 5}
291 skip_fail: false
292
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300293- description: Configure salt.minion on other nodes
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300294 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300295 cfg01*' state.sls salt.minion
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300296 node_name: {{ HOSTNAME_CFG01 }}
297 retry: {count: 3, delay: 5}
298 skip_fail: false
299
300- description: Check salt minion versions on slaves
301 cmd: salt '*' test.version
302 node_name: {{ HOSTNAME_CFG01 }}
303 retry: {count: 1, delay: 5}
304 skip_fail: false
305
306- description: Check salt top states on nodes
307 cmd: salt '*' state.show_top
308 node_name: {{ HOSTNAME_CFG01 }}
309 retry: {count: 1, delay: 5}
310 skip_fail: false
311
312- description: Configure ntp and rsyslog on nodes
313 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog
314 node_name: {{ HOSTNAME_CFG01 }}
315 retry: {count: 1, delay: 10}
316 skip_fail: false
317
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300318- description: Hack gtw node
319 cmd: salt 'gtw*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.110/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 cmp01 node
325 cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
326 node_name: {{ HOSTNAME_CFG01 }}
327 retry: {count: 1, delay: 10}
328 skip_fail: false
329
330- description: Hack cmp02 node
331 cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
332 node_name: {{ HOSTNAME_CFG01 }}
333 retry: {count: 1, delay: 10}
334 skip_fail: false