blob: 3f7a31b6eb37c990c3d4495e9a4807ad1206d62d [file] [log] [blame]
Dennis Dmitrievab83ea42017-05-12 16:52:45 +03001{% from 'virtual-mcp11-ovs-dpdk/underlay.yaml' import HOSTNAME_CFG01 with context %}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +03002{% from 'virtual-mcp11-ovs-dpdk/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;
Matthew Mosesohnd0632b82017-05-30 17:51:30 +030040 for server in github.com; do
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030041 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;
Tatyana Leontovich644446f2017-06-08 13:43:36 +030072 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 Dmitriev99b26fe2017-04-26 12:34:44 +030093- description: Restart salt-master service
94 cmd: |
95 systemctl restart salt-master;
96 node_name: {{ HOSTNAME_CFG01 }}
97 retry: {count: 1, delay: 5}
98 skip_fail: false
99
100{% for ssh in config.underlay.ssh %}
101- description: Configure salt-minion on {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300102 cmd: |
103 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
104 cat << "EOF" >> /etc/salt/minion.d/minion.conf
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300105 id: {{ ssh['node_name'] }}
106 master: {{ config.salt.salt_master_host }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300107 EOF
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300108 eatmydata apt-get install -y salt-minion;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300109 echo "Check for system info and metadata availability ...";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300110 salt-call --no-color grains.items;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300111 salt-call --no-color pillar.items;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300112 node_name: {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300113 retry: {count: 1, delay: 1}
114 skip_fail: false
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300115{% endfor %}
116
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300117
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300118- description: Accept salt keys from all the nodes
119 cmd: salt-key -A -y
120 node_name: {{ HOSTNAME_CFG01 }}
121 retry: {count: 1, delay: 5}
122 skip_fail: true
123
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300124- description: Configure salt adoptors on cfg01
125 cmd: |
126 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
127 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 Leontovichd8bf14f2017-04-19 12:20:50 +0300132# Prepare salt services and nodes settings
133- description: Run 'linux' formula on cfg01
Tatyana Leontovich18013122017-06-09 20:24:50 +0300134 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300135 node_name: {{ HOSTNAME_CFG01 }}
136 retry: {count: 1, delay: 5}
137 skip_fail: false
138
139- description: Run 'openssh' formula on cfg01
140 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
141 -C 'I@salt:master' state.sls openssh;
142 salt --hard-crash --state-output=mixed --state-verbose=False
143 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Tatyana Leontovich18013122017-06-09 20:24:50 +0300144 yes/' /etc/ssh/sshd_config && service ssh reload";
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300145 node_name: {{ HOSTNAME_CFG01 }}
146 retry: {count: 3, delay: 5}
147 skip_fail: false
148
149- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
150 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
151 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
152 node_name: {{ HOSTNAME_CFG01 }}
153 retry: {count: 1, delay: 1}
154 skip_fail: false
155
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300156- description: Run 'salt.master' formula on cfg01
Dennis Dmitrievd9a4aed2017-07-27 09:17:17 +0300157 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 +0300158 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300159 retry: {count: 2, delay: 5}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300160 skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300161
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300162- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
163 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
164 -C 'I@salt:master' state.sls reclass
165 node_name: {{ HOSTNAME_CFG01 }}
166 retry: {count: 1, delay: 5}
167 skip_fail: false
168
169- description: Refresh pillars on all minions
170 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
171 node_name: {{ HOSTNAME_CFG01 }}
172 retry: {count: 1, delay: 5}
173 skip_fail: false
174
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300175- description: Show reclass-salt --top
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300176 cmd: reclass-salt --top
177 node_name: {{ HOSTNAME_CFG01 }}
178 retry: {count: 1, delay: 5}
179 skip_fail: false
180
Tatyana Leontovich18013122017-06-09 20:24:50 +0300181- description: Sync all salt resources
182 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300183 node_name: {{ HOSTNAME_CFG01 }}
184 retry: {count: 1, delay: 5}
185 skip_fail: false
186
Tatyana Leontovich18013122017-06-09 20:24:50 +0300187- description: Configure linux on master
188 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
189 node_name: {{ HOSTNAME_CFG01 }}
190 retry: {count: 1, delay: 5}
191 skip_fail: false
192
193- description: Configure minion on master
Dennis Dmitriev980db162017-07-27 09:40:01 +0300194 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovich18013122017-06-09 20:24:50 +0300195 -C 'I@salt:master' state.sls 'salt.minion'
196 node_name: {{ HOSTNAME_CFG01 }}
197 retry: {count: 3, delay: 10}
198 skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300199
200# Bootstrap all nodes
201
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300202- description: Configure linux on other nodes
Tatyana Leontovich18013122017-06-09 20:24:50 +0300203 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls 'linux'
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300204 node_name: {{ HOSTNAME_CFG01 }}
205 retry: {count: 1, delay: 5}
206 skip_fail: false
207
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300208- description: Configure openssh on all nodes
Tatyana Leontovich18013122017-06-09 20:24:50 +0300209 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls openssh;
210 salt --hard-crash --state-output=mixed --state-verbose=False
211 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
212 yes/' /etc/ssh/sshd_config && service ssh reload"
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300213 node_name: {{ HOSTNAME_CFG01 }}
214 retry: {count: 1, delay: 5}
215 skip_fail: false
216
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300217- description: Configure salt.minion on other nodes
Dennis Dmitriev980db162017-07-27 09:40:01 +0300218 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 +0300219 node_name: {{ HOSTNAME_CFG01 }}
220 retry: {count: 3, delay: 5}
221 skip_fail: false
222
223- description: Check salt minion versions on slaves
224 cmd: salt '*' test.version
225 node_name: {{ HOSTNAME_CFG01 }}
226 retry: {count: 1, delay: 5}
227 skip_fail: false
228
229- description: Check salt top states on nodes
230 cmd: salt '*' state.show_top
231 node_name: {{ HOSTNAME_CFG01 }}
232 retry: {count: 1, delay: 5}
233 skip_fail: false
234
235- description: Configure ntp and rsyslog on nodes
Tatyana Leontovich18013122017-06-09 20:24:50 +0300236 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 +0300237 node_name: {{ HOSTNAME_CFG01 }}
238 retry: {count: 1, delay: 10}
239 skip_fail: false
240
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300241- description: Hack gtw node
242 cmd: salt 'gtw*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4";
243 node_name: {{ HOSTNAME_CFG01 }}
244 retry: {count: 1, delay: 10}
245 skip_fail: false
246
247- description: Hack cmp01 node
248 cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
249 node_name: {{ HOSTNAME_CFG01 }}
250 retry: {count: 1, delay: 10}
251 skip_fail: false
252
253- description: Hack cmp02 node
254 cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
255 node_name: {{ HOSTNAME_CFG01 }}
256 retry: {count: 1, delay: 10}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200257 skip_fail: false