blob: c4c6a8862dad356cd8a914bd32014d408d749c3a [file] [log] [blame]
Dennis Dmitrievab83ea42017-05-12 16:52:45 +03001{% from 'virtual-mcp10-dvr/map.jinja' import HOSTNAME_CFG01 with context %}
Tatyana Leontovich055b5062017-04-03 13:17:25 +03002
3# Install salt to the config node
4
5
Tatyana Leontovich5fd6ed62017-04-04 15:08:29 +03006- description: Configure repository on the cfg01 node
7 cmd:
Tatyana Leontovich3c6aa452017-04-25 15:04:40 +03008 echo "nameserver 172.18.208.44" >> /etc/resolv.conf;
9 echo "nameserver 8.8.8.8" >> /etc/resolv.conf;
Tatyana Leontovich5fd6ed62017-04-04 15:08:29 +030010 which wget >/dev/null || (apt-get update; apt-get install -y wget);
obutenko89aedf82017-08-04 12:50:37 +030011 echo "deb [arch=amd64] http://apt.mirantis.com/xenial nightly salt extra" > /etc/apt/sources.list.d/mcp_salt.list;
12 wget -O - http://apt.mirantis.com/public.gpg | apt-key add -;
Tatyana Leontovich055b5062017-04-03 13:17:25 +030013 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list;
14 wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -;
Tatyana Leontovich055b5062017-04-03 13:17:25 +030015 node_name: {{ HOSTNAME_CFG01 }}
16 retry: {count: 1, delay: 1}
17 skip_fail: false
18
Tatyana Leontovich055b5062017-04-03 13:17:25 +030019- description: Update packages on cfg01
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030020 cmd: apt-get clean; apt-get update
Tatyana Leontovich055b5062017-04-03 13:17:25 +030021 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030022 retry: {count: 1, delay: 1}
Tatyana Leontovich055b5062017-04-03 13:17:25 +030023 skip_fail: false
24
Tatyana Leontovich5fd6ed62017-04-04 15:08:29 +030025- description: Installing salt master on cfg01
26 cmd: apt-get install -y reclass git; apt-get install -y salt-master
Tatyana Leontovich055b5062017-04-03 13:17:25 +030027 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030028 retry: {count: 1, delay: 1}
29 skip_fail: false
30
31- description: Install common packages on cfg01
32 cmd: apt-get install -y python-pip wget curl tmux byobu iputils-ping traceroute htop tree
33 node_name: {{ HOSTNAME_CFG01 }}
34 retry: {count: 1, delay: 1}
Tatyana Leontovich055b5062017-04-03 13:17:25 +030035 skip_fail: false
36
Tatyana Leontovich055b5062017-04-03 13:17:25 +030037- description: Configure salt-master on cfg01
38 cmd: |
39 cat << 'EOF' >> /etc/salt/master.d/master.conf
40 file_roots:
41 base:
42 - /usr/share/salt-formulas/env
43 pillar_opts: False
44 open_mode: True
45 reclass: &reclass
46 storage_type: yaml_fs
47 inventory_base_uri: /srv/salt/reclass
48 ext_pillar:
49 - reclass: *reclass
50 master_tops:
51 reclass: *reclass
52 EOF
53 node_name: {{ HOSTNAME_CFG01 }}
54 retry: {count: 1, delay: 1}
55 skip_fail: false
56
Tatyana Leontovich30a9db12017-04-06 14:28:39 +030057- description: Configure GIT settings and certificates
58 cmd: touch /root/.git_trusted_certs.pem;
59 for server in git.tcpcloud.eu github.com; do
60 openssl s_client -showcerts -connect $server:443 </dev/null
61 | openssl x509 -outform PEM
62 >> /root/.git_trusted_certs.pem;
63 done;
64 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
65 HOME=/root git config --global user.email "tcp-qa@example.com";
66 HOME=/root git config --global user.name "TCP QA";
67 node_name: {{ HOSTNAME_CFG01 }}
68 retry: {count: 1, delay: 1}
69 skip_fail: false
70
71
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030072- description: Clone reclass models with submodules
Tatyana Leontovich055b5062017-04-03 13:17:25 +030073 cmd: |
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030074 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Tatyana Leontovich5fd6ed62017-04-04 15:08:29 +030075 git clone -b master --recurse-submodules https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab /srv/salt/reclass;
76 mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich055b5062017-04-03 13:17:25 +030077 node_name: {{ HOSTNAME_CFG01 }}
78 retry: {count: 1, delay: 1}
79 skip_fail: false
80
81- description: Configure reclass
82 cmd: |
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030083 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
obutenko89aedf82017-08-04 12:50:37 +030084 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial stable salt};
85 FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg};
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030086 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Tatyana Leontovich543afa92017-04-21 14:48:03 +030087 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030088 wget -O - "${FORMULA_GPG}" | apt-key add -;
89 apt-get clean; apt-get update;
90 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
91 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon");
92 echo -e "\nInstalling all required salt formulas\n";
93 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Tatyana Leontovich14f6a1a2017-04-04 17:30:58 +030094 for formula_service in "${formula_services[@]}"; do
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030095 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
96 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
Tatyana Leontovich055b5062017-04-03 13:17:25 +030097 done;
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030098 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
99 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300100 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
Tatyana Leontovich193554a2017-04-04 17:19:13 +0300101
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300102 cat << 'EOF' >> /etc/reclass/reclass-config.yml
103 storage_type: yaml_fs
104 pretty_print: True
105 output: yaml
106 inventory_base_uri: /srv/salt/reclass
107 EOF
108 node_name: {{ HOSTNAME_CFG01 }}
109 retry: {count: 1, delay: 1}
110 skip_fail: false
111
112- description: Configure salt-minion on cfg01
113 cmd: |
114 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
115 cat << "EOF" >> /etc/salt/minion.d/minion.conf
116 id: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich5fd6ed62017-04-04 15:08:29 +0300117 master: 127.0.0.1
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300118 EOF
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300119 apt-get install -y salt-minion;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300120 node_name: {{ HOSTNAME_CFG01 }}
121 retry: {count: 1, delay: 1}
122 skip_fail: false
123
Tatyana Leontovich14f6a1a2017-04-04 17:30:58 +0300124- description: Configure salt adoptors on cfg01
125 cmd: |
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300126 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
Tatyana Leontovich14f6a1a2017-04-04 17:30:58 +0300127 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
128 node_name: {{ HOSTNAME_CFG01 }}
129 retry: {count: 1, delay: 1}
130 skip_fail: false
131
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300132- description: Restart services
133 cmd: |
134 systemctl restart salt-master;
135 systemctl restart salt-minion;
136 echo "Showing system info and metadata ...";
137 salt-call --no-color grains.items;
138 salt-call --no-color pillar.data;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300139 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300140 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300141 skip_fail: false
142
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300143# Prepare salt services and nodes settings
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300144- description: Run 'linux' formula on cfg01
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300145 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300146 -C 'I@salt:master' state.sls linux;
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300147 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300148 retry: {count: 1, delay: 5}
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300149 skip_fail: false
150
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300151- description: Run 'openssh' formula on cfg01
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300152 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300153 -C 'I@salt:master' state.sls openssh;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300154 salt --hard-crash --state-output=mixed --state-verbose=False
155 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
156 yes/' /etc/ssh/sshd_config && service ssh restart";
157 node_name: {{ HOSTNAME_CFG01 }}
158 retry: {count: 3, delay: 5}
159 skip_fail: false
160
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300161- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
162 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
163 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
164 node_name: {{ HOSTNAME_CFG01 }}
165 retry: {count: 1, delay: 1}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300166 skip_fail: false
167
Tatyana Leontovich30a9db12017-04-06 14:28:39 +0300168- description: Run 'reclass' formula on cfg01
169 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
170 -C 'I@salt:master' reclass;
171 salt-call --no-color state.sls salt.master;
172 node_name: {{ HOSTNAME_CFG01 }}
173 retry: {count: 1, delay: 5}
174 skip_fail: true
175
176
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300177- description: Run 'salt' formula on cfg01
178 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300179 -C 'I@salt:master' state.sls salt.master.service;
Tatyana Leontovich30a9db12017-04-06 14:28:39 +0300180 salt-call --no-color state.sls salt.master,salt.api,salt.minion.ca;
181 systemctl restart salt-minion;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300182 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300183 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300184 skip_fail: true
185
186- 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: false
191
192- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
193 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
194 -C 'I@salt:master' state.sls reclass
195 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300196 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300197 skip_fail: false
198
199- description: Refresh pillars on all minions
200 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
201 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300202 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300203 skip_fail: false
204
205- description: Sync all salt resources
206 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
207 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300208 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300209 skip_fail: false
210
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300211- description: Show reclass-salt --top
Tatyana Leontovich30a9db12017-04-06 14:28:39 +0300212 cmd: reclass-salt --top; salt-call --no-color state.sls salt.minion.cert -l info;
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300213 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300214 retry: {count: 1, delay: 5}
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300215 skip_fail: false
216
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300217
218# Bootstrap all nodes
219
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300220- description: Configure linux on controllers
221 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'ctl*' state.sls
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300222 linux
223 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300224 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300225 skip_fail: false
226
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300227- description: Configure linux on proxy
228 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'prx*' state.sls
229 linux
230 node_name: {{ HOSTNAME_CFG01 }}
231 retry: {count: 1, delay: 5}
232 skip_fail: false
233
234- description: Configure linux on gtw
235 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'gtw*' state.sls
236 linux
237 node_name: {{ HOSTNAME_CFG01 }}
238 retry: {count: 3, delay: 20}
239 skip_fail: false
240
241- description: Configure linux on cmp
242 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'cmp*' state.sls
243 linux
244 node_name: {{ HOSTNAME_CFG01 }}
245 retry: {count: 3, delay: 20}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300246 skip_fail: false
247
248- description: Configure openssh on all nodes
249 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
250 cfg*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
251 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
252 yes/' /etc/ssh/sshd_config && service ssh restart"
253 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300254 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300255 skip_fail: false
256
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300257- description: Configure salt.minion on ctl
258 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'ctl*' state.sls salt.minion
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300259 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300260 retry: {count: 3, delay: 5}
261 skip_fail: false
262
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300263- description: Configure salt.minion on prx
264 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'prx*' state.sls salt.minion
265 node_name: {{ HOSTNAME_CFG01 }}
266 retry: {count: 3, delay: 5}
267 skip_fail: false
268
269
270- description: Configure salt.minion on gtw
271 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'gtw*' state.sls salt.minion
272 node_name: {{ HOSTNAME_CFG01 }}
273 retry: {count: 3, delay: 5}
274 skip_fail: false
275
276- description: Configure salt.minion on cmp
277 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'cmp*' state.sls salt.minion
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300278 node_name: {{ HOSTNAME_CFG01 }}
279 retry: {count: 3, delay: 5}
280 skip_fail: false
281
282- description: Check salt minion versions on slaves
283 cmd: salt '*' test.version
284 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300285 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300286 skip_fail: false
287
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300288- description: Check salt top states on nodes
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300289 cmd: salt '*' state.show_top
290 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300291 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300292 skip_fail: false
293
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300294- description: Configure ntp and rsyslog on nodes
295 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300296 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300297 retry: {count: 1, delay: 10}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300298 skip_fail: false
299
Tatyana Leontovich4d0d8942017-04-06 19:10:56 +0300300- description: Hack gtw node
301 cmd: salt 'gtw*' cmd.run "ip addr del 172.16.10.110/24 dev ens4; ip addr flush dev ens4";
302 node_name: {{ HOSTNAME_CFG01 }}
303 retry: {count: 1, delay: 10}
304 skip_fail: false
305
306- description: Hack cmp01 node
307 cmd: salt 'cmp01*' cmd.run "ip addr del 172.16.10.105/24 dev ens4; ip addr flush dev ens4";
308 node_name: {{ HOSTNAME_CFG01 }}
309 retry: {count: 1, delay: 10}
310 skip_fail: false
311
312- description: Hack cmp02 node
313 cmd: salt 'cmp02*' cmd.run "ip addr del 172.16.10.106/24 dev ens4; ip addr flush dev ens4";
314 node_name: {{ HOSTNAME_CFG01 }}
315 retry: {count: 1, delay: 10}
316 skip_fail: false
317