blob: 06b8310adf13d8eb1b396ff5dbb5e5192c73ea0a [file] [log] [blame]
Dennis Dmitrievab83ea42017-05-12 16:52:45 +03001{% from 'virtual-mcp-ocata-ovs/underlay.yaml' import HOSTNAME_CFG01 with context %}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +03002{% from 'virtual-mcp-ocata-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') %}
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
52
53- description: Clone reclass models with submodules
54 cmd: |
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020055{{ SHARED.MACRO_CLONE_RECLASS_MODELS() }}
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030056 # Show the changes to the console
57 cd /srv/salt/reclass/; git diff
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030058 node_name: {{ HOSTNAME_CFG01 }}
59 retry: {count: 1, delay: 1}
60 skip_fail: false
61
62- description: Configure reclass
63 cmd: |
64 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
obutenko89aedf82017-08-04 12:50:37 +030065 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
66 FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg};
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030067 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Tatyana Leontovich543afa92017-04-21 14:48:03 +030068 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030069 wget -O - "${FORMULA_GPG}" | apt-key add -;
70 apt-get clean; apt-get update;
71 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitriev76f65462017-07-20 16:21:26 -040072 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 +030073 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030074 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030075 for formula_service in "${formula_services[@]}"; do
76 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
77 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
78 done;
79 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
80 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
81 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
82
83 cat << 'EOF' >> /etc/reclass/reclass-config.yml
84 storage_type: yaml_fs
85 pretty_print: True
86 output: yaml
87 inventory_base_uri: /srv/salt/reclass
88 EOF
89 node_name: {{ HOSTNAME_CFG01 }}
90 retry: {count: 1, delay: 1}
91 skip_fail: false
92
Dennis Dmitriev9c2707e2017-07-21 13:17:53 +030093- 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 +030094 cmd: |
Dennis Dmitriev9c2707e2017-07-21 13:17:53 +030095 # Remove all other nodes except {{ HOSTNAME_CFG01 }} to not rely on them for 'reclass --top'
96 find /srv/salt/reclass/nodes/ -type f -not -name {{ HOSTNAME_CFG01 }}.yml -delete
97 node_name: {{ HOSTNAME_CFG01 }}
98 retry: {count: 1, delay: 5}
99 skip_fail: false
100
101- description: Show reclass-salt --top for cfg01 node
102 cmd: reclass-salt --top
103 node_name: {{ HOSTNAME_CFG01 }}
104 retry: {count: 1, delay: 5}
105 skip_fail: false
106
107- description: Restart salt-master service
108 cmd: systemctl restart salt-master;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300109 node_name: {{ HOSTNAME_CFG01 }}
110 retry: {count: 1, delay: 5}
111 skip_fail: false
112
113{% for ssh in config.underlay.ssh %}
114- description: Configure salt-minion on {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300115 cmd: |
116 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
117 cat << "EOF" >> /etc/salt/minion.d/minion.conf
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300118 id: {{ ssh['node_name'] }}
119 master: {{ config.salt.salt_master_host }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300120 EOF
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300121 eatmydata apt-get install -y salt-minion;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300122 echo "Check for system info and metadata availability ...";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300123 salt-call --no-color grains.items;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300124 salt-call --no-color pillar.items;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300125 node_name: {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300126 retry: {count: 1, delay: 1}
127 skip_fail: false
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300128{% endfor %}
129
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300130
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300131- description: Accept salt keys from all the nodes
132 cmd: salt-key -A -y
133 node_name: {{ HOSTNAME_CFG01 }}
134 retry: {count: 1, delay: 5}
135 skip_fail: true
136
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300137- description: Configure salt adoptors on cfg01
138 cmd: |
139 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
140 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
141 node_name: {{ HOSTNAME_CFG01 }}
142 retry: {count: 1, delay: 1}
143 skip_fail: false
144
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300145# Prepare salt services and nodes settings
146- description: Run 'linux' formula on cfg01
Tatyana Leontovich18013122017-06-09 20:24:50 +0300147 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300148 node_name: {{ HOSTNAME_CFG01 }}
149 retry: {count: 1, delay: 5}
150 skip_fail: false
151
152- description: Run 'openssh' formula on cfg01
153 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
154 -C 'I@salt:master' state.sls openssh;
155 salt --hard-crash --state-output=mixed --state-verbose=False
156 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Tatyana Leontovich18013122017-06-09 20:24:50 +0300157 yes/' /etc/ssh/sshd_config && service ssh reload";
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300158 node_name: {{ HOSTNAME_CFG01 }}
159 retry: {count: 3, delay: 5}
160 skip_fail: false
161
162- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
163 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
164 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
165 node_name: {{ HOSTNAME_CFG01 }}
166 retry: {count: 1, delay: 1}
167 skip_fail: false
168
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300169- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve4cfced2017-07-27 07:31:21 +0300170 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 +0300171 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300172 retry: {count: 2, delay: 5}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300173 skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300174
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300175- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
176 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
177 -C 'I@salt:master' state.sls reclass
178 node_name: {{ HOSTNAME_CFG01 }}
179 retry: {count: 1, delay: 5}
180 skip_fail: false
181
182- description: Refresh pillars on all minions
183 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
184 node_name: {{ HOSTNAME_CFG01 }}
185 retry: {count: 1, delay: 5}
186 skip_fail: false
187
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300188- description: Show reclass-salt --top
Dennis Dmitriev9c2707e2017-07-21 13:17:53 +0300189 cmd: reclass-salt --top
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300190 node_name: {{ HOSTNAME_CFG01 }}
191 retry: {count: 1, delay: 5}
192 skip_fail: false
193
Tatyana Leontovich18013122017-06-09 20:24:50 +0300194- description: Sync all salt resources
195 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300196 node_name: {{ HOSTNAME_CFG01 }}
197 retry: {count: 1, delay: 5}
198 skip_fail: false
199
Tatyana Leontovich18013122017-06-09 20:24:50 +0300200- description: Configure linux on master
201 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
202 node_name: {{ HOSTNAME_CFG01 }}
203 retry: {count: 1, delay: 5}
204 skip_fail: false
205
206- description: Configure minion on master
Dennis Dmitriev980db162017-07-27 09:40:01 +0300207 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovich18013122017-06-09 20:24:50 +0300208 -C 'I@salt:master' state.sls 'salt.minion'
209 node_name: {{ HOSTNAME_CFG01 }}
210 retry: {count: 3, delay: 10}
211 skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300212
213# Bootstrap all nodes
214
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300215- description: Configure linux on other nodes
Tatyanka Leontovichbbd6b2d2017-07-21 06:02:15 -0400216 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls 'linux'
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300217 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve4cfced2017-07-27 07:31:21 +0300218 retry: {count: 3, delay: 5}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300219 skip_fail: false
220
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300221- description: Configure openssh on all nodes
Tatyana Leontovich18013122017-06-09 20:24:50 +0300222 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls openssh;
223 salt --hard-crash --state-output=mixed --state-verbose=False
Tatyanka Leontovichbbd6b2d2017-07-21 06:02:15 -0400224 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Tatyana Leontovich18013122017-06-09 20:24:50 +0300225 yes/' /etc/ssh/sshd_config && service ssh reload"
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300226 node_name: {{ HOSTNAME_CFG01 }}
227 retry: {count: 1, delay: 5}
228 skip_fail: false
229
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300230- description: Configure salt.minion on other nodes
Dennis Dmitriev980db162017-07-27 09:40:01 +0300231 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 +0300232 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev5b0e5f32017-07-22 11:30:26 +0300233 retry: {count: 3, delay: 15}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300234 skip_fail: false
235
236- description: Check salt minion versions on slaves
237 cmd: salt '*' test.version
238 node_name: {{ HOSTNAME_CFG01 }}
239 retry: {count: 1, delay: 5}
240 skip_fail: false
241
242- description: Check salt top states on nodes
243 cmd: salt '*' state.show_top
244 node_name: {{ HOSTNAME_CFG01 }}
245 retry: {count: 1, delay: 5}
246 skip_fail: false
247
248- description: Configure ntp and rsyslog on nodes
Tatyanka Leontovichbbd6b2d2017-07-21 06:02:15 -0400249 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 +0300250 node_name: {{ HOSTNAME_CFG01 }}
251 retry: {count: 1, delay: 10}
252 skip_fail: false
253
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300254- description: Hack gtw node
255 cmd: salt 'gtw*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4";
256 node_name: {{ HOSTNAME_CFG01 }}
257 retry: {count: 1, delay: 10}
258 skip_fail: false
259
260- description: Hack cmp01 node
261 cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
262 node_name: {{ HOSTNAME_CFG01 }}
263 retry: {count: 1, delay: 10}
264 skip_fail: false
265
266- description: Hack cmp02 node
267 cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
268 node_name: {{ HOSTNAME_CFG01 }}
269 retry: {count: 1, delay: 10}
270 skip_fail: false