blob: 72a3d69f0d8cb014d7f918736768ae8d551d3cc9 [file] [log] [blame]
Dennis Dmitrievab83ea42017-05-12 16:52:45 +03001{% from 'virtual-mcp-ocata-dvr/underlay.yaml' import HOSTNAME_CFG01 with context %}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +03002{% from 'virtual-mcp-ocata-dvr/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') %}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02005# Other salt model repository parameters see in shared-salt.yaml
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +03006
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02007{% import 'shared-salt.yaml' as SHARED with context %}
8{% from 'shared-salt.yaml' import IPV4_NET_CONTROL_PREFIX with context %}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +03009
10# Install salt to the config node
11
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030012- description: Installing salt master on cfg01
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030013 cmd: eatmydata apt-get install -y reclass git salt-master
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030014 node_name: {{ HOSTNAME_CFG01 }}
15 retry: {count: 1, delay: 1}
16 skip_fail: false
17
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030018- description: Configure salt-master on cfg01
19 cmd: |
20 cat << 'EOF' >> /etc/salt/master.d/master.conf
21 file_roots:
22 base:
23 - /usr/share/salt-formulas/env
24 pillar_opts: False
25 open_mode: True
26 reclass: &reclass
27 storage_type: yaml_fs
28 inventory_base_uri: /srv/salt/reclass
29 ext_pillar:
30 - reclass: *reclass
31 master_tops:
32 reclass: *reclass
33 EOF
34 node_name: {{ HOSTNAME_CFG01 }}
35 retry: {count: 1, delay: 1}
36 skip_fail: false
37
38- description: Configure GIT settings and certificates
39 cmd: touch /root/.git_trusted_certs.pem;
40 for server in git.tcpcloud.eu github.com; do
41 openssl s_client -showcerts -connect $server:443 </dev/null
42 | openssl x509 -outform PEM
43 >> /root/.git_trusted_certs.pem;
44 done;
45 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
46 HOME=/root git config --global user.email "tcp-qa@example.com";
47 HOME=/root git config --global user.name "TCP QA";
48 node_name: {{ HOSTNAME_CFG01 }}
49 retry: {count: 1, delay: 1}
50 skip_fail: false
51
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030052- description: Clone reclass models with submodules
53 cmd: |
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020054{{ SHARED.MACRO_CLONE_RECLASS_MODELS() }}
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030055 # Show the changes to the console
56 cd /srv/salt/reclass/; git diff
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030057 node_name: {{ HOSTNAME_CFG01 }}
58 retry: {count: 1, delay: 1}
59 skip_fail: false
60
61- description: Configure reclass
62 cmd: |
63 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
obutenko89aedf82017-08-04 12:50:37 +030064 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
65 FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg};
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030066 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Tatyana Leontovich543afa92017-04-21 14:48:03 +030067 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030068 wget -O - "${FORMULA_GPG}" | apt-key add -;
69 apt-get clean; apt-get update;
70 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitriev76f65462017-07-20 16:21:26 -040071 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch" "powerdns");
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030072 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030073 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030074 for formula_service in "${formula_services[@]}"; do
75 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
76 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
77 done;
78 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
79 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
80 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
81
82 cat << 'EOF' >> /etc/reclass/reclass-config.yml
83 storage_type: yaml_fs
84 pretty_print: True
85 output: yaml
86 inventory_base_uri: /srv/salt/reclass
87 EOF
88 node_name: {{ HOSTNAME_CFG01 }}
89 retry: {count: 1, delay: 1}
90 skip_fail: false
91
Dennis Dmitriev9c2707e2017-07-21 13:17:53 +030092- description: "*Workaround* remove all cfg01 nodes except {{ HOSTNAME_CFG01 }} to not depend on other clusters in 'reclass --top'"
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030093 cmd: |
Dennis Dmitriev9c2707e2017-07-21 13:17:53 +030094 # Remove all other nodes except {{ HOSTNAME_CFG01 }} to not rely on them for 'reclass --top'
95 find /srv/salt/reclass/nodes/ -type f -not -name {{ HOSTNAME_CFG01 }}.yml -delete
96 node_name: {{ HOSTNAME_CFG01 }}
97 retry: {count: 1, delay: 5}
98 skip_fail: false
99
100- description: Show reclass-salt --top for cfg01 node
101 cmd: reclass-salt --top
102 node_name: {{ HOSTNAME_CFG01 }}
103 retry: {count: 1, delay: 5}
104 skip_fail: false
105
106- description: Restart salt-master service
107 cmd: systemctl restart salt-master;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300108 node_name: {{ HOSTNAME_CFG01 }}
109 retry: {count: 1, delay: 5}
110 skip_fail: false
111
112{% for ssh in config.underlay.ssh %}
113- description: Configure salt-minion on {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300114 cmd: |
115 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
116 cat << "EOF" >> /etc/salt/minion.d/minion.conf
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300117 id: {{ ssh['node_name'] }}
118 master: {{ config.salt.salt_master_host }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300119 EOF
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300120 eatmydata apt-get install -y salt-minion;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300121 echo "Check for system info and metadata availability ...";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300122 salt-call --no-color grains.items;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300123 salt-call --no-color pillar.items;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300124 node_name: {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300125 retry: {count: 1, delay: 1}
126 skip_fail: false
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300127{% endfor %}
128
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300129- description: Accept salt keys from all the nodes
130 cmd: salt-key -A -y
131 node_name: {{ HOSTNAME_CFG01 }}
132 retry: {count: 1, delay: 5}
133 skip_fail: true
134
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300135- description: Configure salt adoptors on cfg01
136 cmd: |
137 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
138 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
139 node_name: {{ HOSTNAME_CFG01 }}
140 retry: {count: 1, delay: 1}
141 skip_fail: false
142
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300143# Prepare salt services and nodes settings
144- description: Run 'linux' formula on cfg01
Tatyana Leontovich18013122017-06-09 20:24:50 +0300145 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300146 node_name: {{ HOSTNAME_CFG01 }}
147 retry: {count: 1, delay: 5}
148 skip_fail: false
149
150- description: Run 'openssh' formula on cfg01
151 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
152 -C 'I@salt:master' state.sls openssh;
153 salt --hard-crash --state-output=mixed --state-verbose=False
154 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Tatyana Leontovich18013122017-06-09 20:24:50 +0300155 yes/' /etc/ssh/sshd_config && service ssh reload";
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300156 node_name: {{ HOSTNAME_CFG01 }}
157 retry: {count: 3, delay: 5}
158 skip_fail: false
159
160- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
161 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
162 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
163 node_name: {{ HOSTNAME_CFG01 }}
164 retry: {count: 1, delay: 1}
165 skip_fail: false
166
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300167- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve4cfced2017-07-27 07:31:21 +0300168 cmd: timeout 120 salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300169 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300170 retry: {count: 2, delay: 5}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300171 skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300172
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300173- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
174 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
175 -C 'I@salt:master' state.sls reclass
176 node_name: {{ HOSTNAME_CFG01 }}
177 retry: {count: 1, delay: 5}
178 skip_fail: false
179
180- description: Refresh pillars on all minions
181 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
182 node_name: {{ HOSTNAME_CFG01 }}
183 retry: {count: 1, delay: 5}
184 skip_fail: false
185
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300186- description: Show reclass-salt --top
Dennis Dmitriev9c2707e2017-07-21 13:17:53 +0300187 cmd: reclass-salt --top
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300188 node_name: {{ HOSTNAME_CFG01 }}
189 retry: {count: 1, delay: 5}
190 skip_fail: false
191
Tatyana Leontovich18013122017-06-09 20:24:50 +0300192- description: Sync all salt resources
193 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300194 node_name: {{ HOSTNAME_CFG01 }}
195 retry: {count: 1, delay: 5}
196 skip_fail: false
197
Tatyana Leontovich18013122017-06-09 20:24:50 +0300198- description: Configure linux on master
199 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
200 node_name: {{ HOSTNAME_CFG01 }}
201 retry: {count: 1, delay: 5}
202 skip_fail: false
203
204- description: Configure minion on master
Dennis Dmitriev980db162017-07-27 09:40:01 +0300205 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovich18013122017-06-09 20:24:50 +0300206 -C 'I@salt:master' state.sls 'salt.minion'
207 node_name: {{ HOSTNAME_CFG01 }}
208 retry: {count: 3, delay: 10}
209 skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300210
211# Bootstrap all nodes
212
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300213- description: Configure linux on other nodes
Tatyanka Leontovichbbd6b2d2017-07-21 06:02:15 -0400214 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls 'linux'
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300215 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve4cfced2017-07-27 07:31:21 +0300216 retry: {count: 3, delay: 5}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300217 skip_fail: false
218
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300219- description: Configure openssh on all nodes
Tatyanka Leontovichbbd6b2d2017-07-21 06:02:15 -0400220 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls openssh;
Tatyana Leontovich18013122017-06-09 20:24:50 +0300221 salt --hard-crash --state-output=mixed --state-verbose=False
Tatyanka Leontovichbbd6b2d2017-07-21 06:02:15 -0400222 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Tatyana Leontovich18013122017-06-09 20:24:50 +0300223 yes/' /etc/ssh/sshd_config && service ssh reload"
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300224 node_name: {{ HOSTNAME_CFG01 }}
225 retry: {count: 1, delay: 5}
226 skip_fail: false
227
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300228- description: Configure salt.minion on other nodes
Dennis Dmitriev980db162017-07-27 09:40:01 +0300229 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300230 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev5b0e5f32017-07-22 11:30:26 +0300231 retry: {count: 3, delay: 15}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300232 skip_fail: false
233
234- description: Check salt minion versions on slaves
235 cmd: salt '*' test.version
236 node_name: {{ HOSTNAME_CFG01 }}
237 retry: {count: 1, delay: 5}
238 skip_fail: false
239
240- description: Check salt top states on nodes
241 cmd: salt '*' state.show_top
242 node_name: {{ HOSTNAME_CFG01 }}
243 retry: {count: 1, delay: 5}
244 skip_fail: false
245
246- description: Configure ntp and rsyslog on nodes
Tatyanka Leontovichbbd6b2d2017-07-21 06:02:15 -0400247 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300248 node_name: {{ HOSTNAME_CFG01 }}
249 retry: {count: 1, delay: 10}
250 skip_fail: false
251
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300252- description: Hack gtw node
253 cmd: salt 'gtw*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4";
254 node_name: {{ HOSTNAME_CFG01 }}
255 retry: {count: 1, delay: 10}
256 skip_fail: false
257
258- description: Hack cmp01 node
259 cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
260 node_name: {{ HOSTNAME_CFG01 }}
261 retry: {count: 1, delay: 10}
262 skip_fail: false
263
264- description: Hack cmp02 node
265 cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
266 node_name: {{ HOSTNAME_CFG01 }}
267 retry: {count: 1, delay: 10}
268 skip_fail: false