blob: b878e6516abcd6b5bb5f46225fdf77b5be522de2 [file] [log] [blame]
Tatyana Leontovichef147782017-04-05 16:05:11 +03001{% from 'virtual-mcp10-ovs.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:
8 echo "172.18.248.114 jenkins.mcp.mirantis.net gerrit.mcp.mirantis.net" >> /etc/hosts;
9 echo "185.135.196.10 apt-mk.mirantis.com" >> /etc/hosts;
10 echo "nameserver 172.18.208.44 >> /etc/resolv.conf;
11 echo "nameserver 8.8.8.8 >> /etc/resolv.conf;
12 which wget >/dev/null || (apt-get update; apt-get install -y wget);
13 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial nightly salt extra" > /etc/apt/sources.list.d/mcp_salt.list;
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030014 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -;
Tatyana Leontovich055b5062017-04-03 13:17:25 +030015 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list;
16 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 +030017 node_name: {{ HOSTNAME_CFG01 }}
18 retry: {count: 1, delay: 1}
19 skip_fail: false
20
Tatyana Leontovich055b5062017-04-03 13:17:25 +030021- description: Update packages on cfg01
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030022 cmd: apt-get clean; apt-get update
Tatyana Leontovich055b5062017-04-03 13:17:25 +030023 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030024 retry: {count: 1, delay: 1}
Tatyana Leontovich055b5062017-04-03 13:17:25 +030025 skip_fail: false
26
Tatyana Leontovich5fd6ed62017-04-04 15:08:29 +030027- description: Installing salt master on cfg01
28 cmd: apt-get install -y reclass git; apt-get install -y salt-master
Tatyana Leontovich055b5062017-04-03 13:17:25 +030029 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030030 retry: {count: 1, delay: 1}
31 skip_fail: false
32
33- description: Install common packages on cfg01
34 cmd: apt-get install -y python-pip wget curl tmux byobu iputils-ping traceroute htop tree
35 node_name: {{ HOSTNAME_CFG01 }}
36 retry: {count: 1, delay: 1}
Tatyana Leontovich055b5062017-04-03 13:17:25 +030037 skip_fail: false
38
Tatyana Leontovich055b5062017-04-03 13:17:25 +030039- description: Configure salt-master on cfg01
40 cmd: |
41 cat << 'EOF' >> /etc/salt/master.d/master.conf
42 file_roots:
43 base:
44 - /usr/share/salt-formulas/env
45 pillar_opts: False
46 open_mode: True
47 reclass: &reclass
48 storage_type: yaml_fs
49 inventory_base_uri: /srv/salt/reclass
50 ext_pillar:
51 - reclass: *reclass
52 master_tops:
53 reclass: *reclass
54 EOF
55 node_name: {{ HOSTNAME_CFG01 }}
56 retry: {count: 1, delay: 1}
57 skip_fail: false
58
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030059- description: Clone reclass models with submodules
Tatyana Leontovich055b5062017-04-03 13:17:25 +030060 cmd: |
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030061 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Tatyana Leontovich5fd6ed62017-04-04 15:08:29 +030062 git clone -b master --recurse-submodules https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab /srv/salt/reclass;
63 mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich055b5062017-04-03 13:17:25 +030064 node_name: {{ HOSTNAME_CFG01 }}
65 retry: {count: 1, delay: 1}
66 skip_fail: false
67
68- description: Configure reclass
69 cmd: |
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030070 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
71 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.tcpcloud.eu/nightly xenial tcp-salt};
72 FORMULA_GPG=${FORMULA_GPG:-http://apt.tcpcloud.eu/public.gpg};
73 which wget > /dev/null || (apt-get update; apt-get install -y wget);
74 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/tcpcloud_salt.list;
75 wget -O - "${FORMULA_GPG}" | apt-key add -;
76 apt-get clean; apt-get update;
77 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
78 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon");
79 echo -e "\nInstalling all required salt formulas\n";
80 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Tatyana Leontovich14f6a1a2017-04-04 17:30:58 +030081 for formula_service in "${formula_services[@]}"; do
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030082 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
83 [ ! -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 +030084 done;
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030085 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
86 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
Tatyana Leontovich055b5062017-04-03 13:17:25 +030087 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
Tatyana Leontovich193554a2017-04-04 17:19:13 +030088
Tatyana Leontovich055b5062017-04-03 13:17:25 +030089 cat << 'EOF' >> /etc/reclass/reclass-config.yml
90 storage_type: yaml_fs
91 pretty_print: True
92 output: yaml
93 inventory_base_uri: /srv/salt/reclass
94 EOF
95 node_name: {{ HOSTNAME_CFG01 }}
96 retry: {count: 1, delay: 1}
97 skip_fail: false
98
99- description: Configure salt-minion on cfg01
100 cmd: |
101 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
102 cat << "EOF" >> /etc/salt/minion.d/minion.conf
103 id: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich5fd6ed62017-04-04 15:08:29 +0300104 master: 127.0.0.1
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300105 EOF
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300106 apt-get install -y salt-minion;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300107 node_name: {{ HOSTNAME_CFG01 }}
108 retry: {count: 1, delay: 1}
109 skip_fail: false
110
Tatyana Leontovich14f6a1a2017-04-04 17:30:58 +0300111- description: Configure salt adoptors on cfg01
112 cmd: |
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300113 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
Tatyana Leontovich14f6a1a2017-04-04 17:30:58 +0300114 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
115 node_name: {{ HOSTNAME_CFG01 }}
116 retry: {count: 1, delay: 1}
117 skip_fail: false
118
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300119- description: Restart services
120 cmd: |
121 systemctl restart salt-master;
122 systemctl restart salt-minion;
123 echo "Showing system info and metadata ...";
124 salt-call --no-color grains.items;
125 salt-call --no-color pillar.data;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300126 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300127 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300128 skip_fail: false
129
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300130# Prepare salt services and nodes settings
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300131- description: Run 'linux' formula on cfg01
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300132 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300133 -C 'I@salt:master' state.sls linux;
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300134 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300135 retry: {count: 1, delay: 5}
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300136 skip_fail: false
137
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300138- description: Run 'openssh' formula on cfg01
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300139 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300140 -C 'I@salt:master' state.sls openssh;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300141 salt --hard-crash --state-output=mixed --state-verbose=False
142 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
143 yes/' /etc/ssh/sshd_config && service ssh restart";
144 node_name: {{ HOSTNAME_CFG01 }}
145 retry: {count: 3, delay: 5}
146 skip_fail: false
147
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300148- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
149 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
150 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
151 node_name: {{ HOSTNAME_CFG01 }}
152 retry: {count: 1, delay: 1}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300153 skip_fail: false
154
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300155- description: Run 'salt' formula on cfg01
156 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300157 -C 'I@salt:master' state.sls salt.master.service;
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300158 salt-call --no-color state.sls salt.master;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300159 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300160 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300161 skip_fail: true
162
163- description: Accept salt keys from all the nodes
164 cmd: salt-key -A -y
165 node_name: {{ HOSTNAME_CFG01 }}
166 retry: {count: 1, delay: 5}
167 skip_fail: false
168
169- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
170 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
171 -C 'I@salt:master' state.sls reclass
172 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300173 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300174 skip_fail: false
175
176- description: Refresh pillars on all minions
177 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
178 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300179 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300180 skip_fail: false
181
182- description: Sync all salt resources
183 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
184 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300185 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300186 skip_fail: false
187
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300188- description: Show reclass-salt --top
Tatyana Leontovich7c8d9b82017-04-06 14:05:39 +0300189 cmd: reclass-salt --top
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300190 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300191 retry: {count: 1, delay: 5}
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300192 skip_fail: false
193
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300194
195# Bootstrap all nodes
196
197- description: Workaround for missing kernel modules
198 cmd: salt '*' cmd.run "for module in nf_conntrack_ipv4 ip_tables
199 x_tables nf_defrag_ipv4 nf_nat_ipv4 nf_nat
200 iptable_filter iptable_mangle iptable_nat;
201 do
202 modprobe \$module;
203 echo \$module >> /etc/modules;
204 done"
205 node_name: {{ HOSTNAME_CFG01 }}
206 retry: {count: 1, delay: 1}
207 skip_fail: false
208
209
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300210- description: Configure linux on controllers
211 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'ctl*' state.sls
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300212 linux
213 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300214 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300215 skip_fail: false
216
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300217- description: Configure linux on proxy
218 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'prx*' state.sls
219 linux
220 node_name: {{ HOSTNAME_CFG01 }}
221 retry: {count: 1, delay: 5}
222 skip_fail: false
223
224- description: Configure linux on gtw
225 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'gtw*' state.sls
226 linux
227 node_name: {{ HOSTNAME_CFG01 }}
228 retry: {count: 3, delay: 20}
229 skip_fail: false
230
231- description: Configure linux on cmp
232 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'cmp*' state.sls
233 linux
234 node_name: {{ HOSTNAME_CFG01 }}
235 retry: {count: 3, delay: 20}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300236 skip_fail: false
237
238- description: Configure openssh on all nodes
239 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
240 cfg*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
241 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
242 yes/' /etc/ssh/sshd_config && service ssh restart"
243 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300244 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300245 skip_fail: false
246
247- description: '*Workaround* for the bug https://mirantis.jira.com/browse/PROD-8021'
248 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' cmd.run 'apt-get
249 -y install linux-image-extra-$(uname -r)'
250 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300251 retry: {count: 2, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300252 skip_fail: false
253
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300254- description: Configure salt.minion on ctl
255 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'ctl*' state.sls salt.minion
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300256 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300257 retry: {count: 3, delay: 5}
258 skip_fail: false
259
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300260- description: Configure salt.minion on prx
261 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'prx*' state.sls salt.minion
262 node_name: {{ HOSTNAME_CFG01 }}
263 retry: {count: 3, delay: 5}
264 skip_fail: false
265
266
267- description: Configure salt.minion on gtw
268 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'gtw*' state.sls salt.minion
269 node_name: {{ HOSTNAME_CFG01 }}
270 retry: {count: 3, delay: 5}
271 skip_fail: false
272
273- description: Configure salt.minion on cmp
274 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'cmp*' state.sls salt.minion
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300275 node_name: {{ HOSTNAME_CFG01 }}
276 retry: {count: 3, delay: 5}
277 skip_fail: false
278
279- description: Check salt minion versions on slaves
280 cmd: salt '*' test.version
281 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300282 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300283 skip_fail: false
284
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300285- description: Check salt top states on nodes
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300286 cmd: salt '*' state.show_top
287 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300288 retry: {count: 1, delay: 5}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300289 skip_fail: false
290
Tatyana Leontovichdb84b992017-04-05 21:12:52 +0300291- description: Configure ntp and rsyslog on nodes
292 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300293 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich81128412017-04-05 18:46:29 +0300294 retry: {count: 1, delay: 10}
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300295 skip_fail: false
296