blob: a5d61773568f23ff66208ccb8f7005cb14e4a49b [file] [log] [blame]
Dennis Dmitrievab83ea42017-05-12 16:52:45 +03001{% from 'virtual-mcp11-ovs/underlay.yaml' import HOSTNAME_CFG01 with context %}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +03002{% from 'virtual-mcp11-ovs/underlay.yaml' import REPOSITORY_SUITE with context %}
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +03003
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02004
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +03005{% 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 +02006# Other salt model repository parameters see in shared-salt.yaml
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +03007
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02008{% import 'shared-salt.yaml' as SHARED with context %}
9{% from 'shared-salt.yaml' import IPV4_NET_CONTROL_PREFIX with context %}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030010
11# Install salt to the config node
12
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030013- description: Installing salt master on cfg01
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030014 cmd: eatmydata apt-get install -y reclass git salt-master
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030015 node_name: {{ HOSTNAME_CFG01 }}
16 retry: {count: 1, delay: 1}
17 skip_fail: false
18
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030019- description: Configure salt-master on cfg01
20 cmd: |
21 cat << 'EOF' >> /etc/salt/master.d/master.conf
22 file_roots:
23 base:
24 - /usr/share/salt-formulas/env
25 pillar_opts: False
26 open_mode: True
27 reclass: &reclass
28 storage_type: yaml_fs
29 inventory_base_uri: /srv/salt/reclass
30 ext_pillar:
31 - reclass: *reclass
32 master_tops:
33 reclass: *reclass
34 EOF
35 node_name: {{ HOSTNAME_CFG01 }}
36 retry: {count: 1, delay: 1}
37 skip_fail: false
38
39- description: Configure GIT settings and certificates
40 cmd: touch /root/.git_trusted_certs.pem;
Matthew Mosesohnd0632b82017-05-30 17:51:30 +030041 for server in github.com; do
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030042 openssl s_client -showcerts -connect $server:443 </dev/null
43 | openssl x509 -outform PEM
44 >> /root/.git_trusted_certs.pem;
45 done;
46 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
47 HOME=/root git config --global user.email "tcp-qa@example.com";
48 HOME=/root git config --global user.name "TCP QA";
49 node_name: {{ HOSTNAME_CFG01 }}
50 retry: {count: 1, delay: 1}
51 skip_fail: false
52
53
54- description: Clone reclass models with submodules
55 cmd: |
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020056{{ SHARED.MACRO_CLONE_RECLASS_MODELS() }}
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030057 # Show the changes to the console
58 cd /srv/salt/reclass/; git diff
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030059 node_name: {{ HOSTNAME_CFG01 }}
60 retry: {count: 1, delay: 1}
61 skip_fail: false
62
63- description: Configure reclass
64 cmd: |
65 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
obutenko89aedf82017-08-04 12:50:37 +030066 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
67 FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg};
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030068 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Tatyana Leontovich543afa92017-04-21 14:48:03 +030069 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030070 wget -O - "${FORMULA_GPG}" | apt-key add -;
71 apt-get clean; apt-get update;
72 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich644446f2017-06-08 13:43:36 +030073 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 +030074 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030075 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030076 for formula_service in "${formula_services[@]}"; do
77 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
78 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
79 done;
80 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
81 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
82 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
83
84 cat << 'EOF' >> /etc/reclass/reclass-config.yml
85 storage_type: yaml_fs
86 pretty_print: True
87 output: yaml
88 inventory_base_uri: /srv/salt/reclass
89 EOF
90 node_name: {{ HOSTNAME_CFG01 }}
91 retry: {count: 1, delay: 1}
92 skip_fail: false
93
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030094- description: Restart salt-master service
95 cmd: |
96 systemctl restart salt-master;
97 node_name: {{ HOSTNAME_CFG01 }}
98 retry: {count: 1, delay: 5}
99 skip_fail: false
100
101{% for ssh in config.underlay.ssh %}
102- description: Configure salt-minion on {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300103 cmd: |
104 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
105 cat << "EOF" >> /etc/salt/minion.d/minion.conf
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300106 id: {{ ssh['node_name'] }}
107 master: {{ config.salt.salt_master_host }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300108 EOF
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300109 eatmydata apt-get install -y salt-minion;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300110 echo "Check for system info and metadata availability ...";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300111 salt-call --no-color grains.items;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300112 salt-call --no-color pillar.items;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300113 node_name: {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300114 retry: {count: 1, delay: 1}
115 skip_fail: false
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300116{% endfor %}
117
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300118
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300119- description: Accept salt keys from all the nodes
120 cmd: salt-key -A -y
121 node_name: {{ HOSTNAME_CFG01 }}
122 retry: {count: 1, delay: 5}
123 skip_fail: true
124
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300125- description: Configure salt adoptors on cfg01
126 cmd: |
127 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
128 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
129 node_name: {{ HOSTNAME_CFG01 }}
130 retry: {count: 1, delay: 1}
131 skip_fail: false
132
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300133# Prepare salt services and nodes settings
134- description: Run 'linux' formula on cfg01
Tatyana Leontovich18013122017-06-09 20:24:50 +0300135 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300136 node_name: {{ HOSTNAME_CFG01 }}
137 retry: {count: 1, delay: 5}
138 skip_fail: false
139
140- description: Run 'openssh' formula on cfg01
141 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
142 -C 'I@salt:master' state.sls openssh;
143 salt --hard-crash --state-output=mixed --state-verbose=False
144 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Tatyana Leontovich18013122017-06-09 20:24:50 +0300145 yes/' /etc/ssh/sshd_config && service ssh reload";
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300146 node_name: {{ HOSTNAME_CFG01 }}
147 retry: {count: 3, delay: 5}
148 skip_fail: false
149
150- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
151 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
152 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
153 node_name: {{ HOSTNAME_CFG01 }}
154 retry: {count: 1, delay: 1}
155 skip_fail: false
156
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300157- description: Run 'salt.master' formula on cfg01
Dennis Dmitrievd9a4aed2017-07-27 09:17:17 +0300158 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 +0300159 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300160 retry: {count: 2, delay: 5}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300161 skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300162
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300163- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
164 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
165 -C 'I@salt:master' state.sls reclass
166 node_name: {{ HOSTNAME_CFG01 }}
167 retry: {count: 1, delay: 5}
168 skip_fail: false
169
170- description: Refresh pillars on all minions
171 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
172 node_name: {{ HOSTNAME_CFG01 }}
173 retry: {count: 1, delay: 5}
174 skip_fail: false
175
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300176- description: Show reclass-salt --top
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300177 cmd: reclass-salt --top
178 node_name: {{ HOSTNAME_CFG01 }}
179 retry: {count: 1, delay: 5}
180 skip_fail: false
181
Tatyana Leontovich18013122017-06-09 20:24:50 +0300182- description: Sync all salt resources
183 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300184 node_name: {{ HOSTNAME_CFG01 }}
185 retry: {count: 1, delay: 5}
186 skip_fail: false
187
Tatyana Leontovich18013122017-06-09 20:24:50 +0300188- description: Configure linux on master
189 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
190 node_name: {{ HOSTNAME_CFG01 }}
191 retry: {count: 1, delay: 5}
192 skip_fail: false
193
194- description: Configure minion on master
Dennis Dmitriev980db162017-07-27 09:40:01 +0300195 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovich18013122017-06-09 20:24:50 +0300196 -C 'I@salt:master' state.sls 'salt.minion'
197 node_name: {{ HOSTNAME_CFG01 }}
198 retry: {count: 3, delay: 10}
199 skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300200
201# Bootstrap all nodes
202
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300203- description: Configure linux on other nodes
Tatyana Leontovich18013122017-06-09 20:24:50 +0300204 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls 'linux'
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300205 node_name: {{ HOSTNAME_CFG01 }}
206 retry: {count: 1, delay: 5}
207 skip_fail: false
208
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300209- description: Configure openssh on all nodes
Tatyana Leontovich18013122017-06-09 20:24:50 +0300210 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls openssh;
211 salt --hard-crash --state-output=mixed --state-verbose=False
212 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
213 yes/' /etc/ssh/sshd_config && service ssh reload"
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300214 node_name: {{ HOSTNAME_CFG01 }}
215 retry: {count: 1, delay: 5}
216 skip_fail: false
217
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300218- description: Configure salt.minion on other nodes
Dennis Dmitriev980db162017-07-27 09:40:01 +0300219 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 +0300220 node_name: {{ HOSTNAME_CFG01 }}
221 retry: {count: 3, delay: 5}
222 skip_fail: false
223
224- description: Check salt minion versions on slaves
225 cmd: salt '*' test.version
226 node_name: {{ HOSTNAME_CFG01 }}
227 retry: {count: 1, delay: 5}
228 skip_fail: false
229
230- description: Check salt top states on nodes
231 cmd: salt '*' state.show_top
232 node_name: {{ HOSTNAME_CFG01 }}
233 retry: {count: 1, delay: 5}
234 skip_fail: false
235
236- description: Configure ntp and rsyslog on nodes
Tatyana Leontovich18013122017-06-09 20:24:50 +0300237 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 +0300238 node_name: {{ HOSTNAME_CFG01 }}
239 retry: {count: 1, delay: 10}
240 skip_fail: false
241
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300242- description: Hack gtw node
243 cmd: salt 'gtw*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4";
244 node_name: {{ HOSTNAME_CFG01 }}
245 retry: {count: 1, delay: 10}
246 skip_fail: false
247
248- description: Hack cmp01 node
249 cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
250 node_name: {{ HOSTNAME_CFG01 }}
251 retry: {count: 1, delay: 10}
252 skip_fail: false
253
254- description: Hack cmp02 node
255 cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
256 node_name: {{ HOSTNAME_CFG01 }}
257 retry: {count: 1, delay: 10}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200258 skip_fail: false