blob: 353715313ee9667d64862c8c2e4bbdb2398b3d1a [file] [log] [blame]
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +03001{% from 'virtual-mcp11-k8s-calico/underlay.yaml' import HOSTNAME_CFG01 with context %}
2{% from 'virtual-mcp11-k8s-calico/underlay.yaml' import REPOSITORY_SUITE with context %}
3
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
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +03006
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02007{% import 'shared-salt.yaml' as SHARED with context %}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +02008
9# Install salt to the config node
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020010- description: Installing salt master on cfg01
11 cmd: apt-get install -y reclass git; apt-get install -y salt-master
12 node_name: {{ HOSTNAME_CFG01 }}
13 retry: {count: 1, delay: 1}
14 skip_fail: false
15
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020016- description: Configure salt-master on cfg01
17 cmd: |
18 cat << 'EOF' >> /etc/salt/master.d/master.conf
19 file_roots:
20 base:
21 - /usr/share/salt-formulas/env
22 pillar_opts: False
23 open_mode: True
24 reclass: &reclass
25 storage_type: yaml_fs
26 inventory_base_uri: /srv/salt/reclass
27 ext_pillar:
28 - reclass: *reclass
29 master_tops:
30 reclass: *reclass
31 EOF
32 node_name: {{ HOSTNAME_CFG01 }}
33 retry: {count: 1, delay: 1}
34 skip_fail: false
35
36- description: Configure GIT settings and certificates
37 cmd: touch /root/.git_trusted_certs.pem;
Matthew Mosesohnd0632b82017-05-30 17:51:30 +030038 for server in github.com; do
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020039 openssl s_client -showcerts -connect $server:443 </dev/null
40 | openssl x509 -outform PEM
41 >> /root/.git_trusted_certs.pem;
42 done;
43 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
44 HOME=/root git config --global user.email "tcp-qa@example.com";
45 HOME=/root git config --global user.name "TCP QA";
46 node_name: {{ HOSTNAME_CFG01 }}
47 retry: {count: 1, delay: 1}
48 skip_fail: false
49
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020050- description: Clone reclass models with submodules
Tatyana Leontovichcf37cb22017-05-19 14:59:38 +030051 cmd: |
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020052{{ SHARED.MACRO_CLONE_RECLASS_MODELS() }}
Tatyana Leontovichcf37cb22017-05-19 14:59:38 +030053 # Show the changes to the console
54 cd /srv/salt/reclass/; git diff
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020055 node_name: {{ HOSTNAME_CFG01 }}
56 retry: {count: 1, delay: 1}
57 skip_fail: false
58
59- description: Configure reclass
60 cmd: |
61 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
obutenko89aedf82017-08-04 12:50:37 +030062 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
63 FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg};
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020064 which wget > /dev/null || (apt-get update; apt-get install -y wget);
65 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
66 wget -O - "${FORMULA_GPG}" | apt-key add -;
67 apt-get clean; apt-get update;
68 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich644446f2017-06-08 13:43:36 +030069 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch");
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020070 echo -e "\nInstalling all required salt formulas\n";
Tatyana Leontovich573584a2017-05-19 14:54:00 +030071 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020072 for formula_service in "${formula_services[@]}"; do
73 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
74 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
75 done;
76 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
77 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
78 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
79
80 cat << 'EOF' >> /etc/reclass/reclass-config.yml
81 storage_type: yaml_fs
82 pretty_print: True
83 output: yaml
84 inventory_base_uri: /srv/salt/reclass
85 EOF
86 node_name: {{ HOSTNAME_CFG01 }}
87 retry: {count: 1, delay: 1}
88 skip_fail: false
89
Tatyana Leontovich573584a2017-05-19 14:54:00 +030090- description: Restart salt-master service
91 cmd: |
92 systemctl restart salt-master;
93 node_name: {{ HOSTNAME_CFG01 }}
94 retry: {count: 1, delay: 5}
95 skip_fail: false
96
97{% for ssh in config.underlay.ssh %}
98- description: Configure salt-minion on {{ ssh['node_name'] }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020099 cmd: |
100 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
101 cat << "EOF" >> /etc/salt/minion.d/minion.conf
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300102 id: {{ ssh['node_name'] }}
103 master: {{ config.salt.salt_master_host }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200104 EOF
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300105 eatmydata apt-get install -y salt-minion;
106 echo "Check for system info and metadata availability ...";
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +0200107 salt-call --hard-crash --no-color grains.items;
108 salt-call --hard-crash --no-color pillar.items;
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300109 node_name: {{ ssh['node_name'] }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200110 retry: {count: 1, delay: 1}
111 skip_fail: false
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300112{% endfor %}
113
114- description: Accept salt keys from all the nodes
115 cmd: salt-key -A -y
116 node_name: {{ HOSTNAME_CFG01 }}
117 retry: {count: 1, delay: 5}
118 skip_fail: true
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200119
120- description: Configure salt adoptors on cfg01
121 cmd: |
122 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
123 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
124 node_name: {{ HOSTNAME_CFG01 }}
125 retry: {count: 1, delay: 1}
126 skip_fail: false
127
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200128# Prepare salt services and nodes settings
129- description: Run 'linux' formula on cfg01
130 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
131 -C 'I@salt:master' state.sls linux;
132 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +0200133 retry: {count: 2, delay: 5}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200134 skip_fail: false
135
136- description: Run 'openssh' formula on cfg01
137 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
138 -C 'I@salt:master' state.sls openssh;
139 salt --hard-crash --state-output=mixed --state-verbose=False
140 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
141 yes/' /etc/ssh/sshd_config && service ssh restart";
142 node_name: {{ HOSTNAME_CFG01 }}
143 retry: {count: 3, delay: 5}
144 skip_fail: false
145
146- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
147 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
148 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
149 node_name: {{ HOSTNAME_CFG01 }}
150 retry: {count: 1, delay: 1}
151 skip_fail: false
152
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300153- description: Run 'salt.master' formula on cfg01
Dennis Dmitrievd9a4aed2017-07-27 09:17:17 +0300154 cmd: timeout 120 salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +0200155 -C 'I@salt:master' state.sls salt.master;
Tatyana Leontovich1c568f92017-07-03 15:16:27 +0300156 node_name: {{ HOSTNAME_CFG01 }}
157 retry: {count: 2, delay: 5}
158 skip_fail: false
159
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200160- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
161 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
162 -C 'I@salt:master' state.sls reclass
163 node_name: {{ HOSTNAME_CFG01 }}
164 retry: {count: 1, delay: 5}
165 skip_fail: false
166
167- description: Refresh pillars on all minions
168 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
169 node_name: {{ HOSTNAME_CFG01 }}
170 retry: {count: 1, delay: 5}
171 skip_fail: false
172
Sergii Golovatiuk5b659d42017-05-26 17:38:06 +0200173- description: Show reclass-salt --top
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300174 cmd: reclass-salt --top
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200175 node_name: {{ HOSTNAME_CFG01 }}
176 retry: {count: 1, delay: 5}
177 skip_fail: false
178
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +0200179- description: Sync all salt resources
180 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300181 node_name: {{ HOSTNAME_CFG01 }}
182 retry: {count: 1, delay: 5}
183 skip_fail: false
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200184
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +0200185- description: Configure linux on master
186 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
187 -C 'I@salt:master' state.sls 'linux.system'
188 node_name: {{ HOSTNAME_CFG01 }}
189 retry: {count: 1, delay: 5}
190 skip_fail: false
191
192- description: Configure minion on master
193 cmd: salt-call --hard-crash -l debug state.sls 'salt.minion'
194 node_name: {{ HOSTNAME_CFG01 }}
195 retry: {count: 3, delay: 10}
196 skip_fail: false
197
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200198# Bootstrap all nodes
199
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300200- description: Configure linux on other nodes
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +0200201 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
202 -C 'I@linux:system' state.sls 'linux'
203 node_name: {{ HOSTNAME_CFG01 }}
204 retry: {count: 3, delay: 5}
205 skip_fail: false
206
207- description: Configure openssh on all nodes
208 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
209 -C 'I@linux:system' state.sls openssh;
210 salt --hard-crash --state-output=mixed --state-verbose=False
211 -C 'I@linux:system' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
212 yes/' /etc/ssh/sshd_config && service ssh reload"
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200213 node_name: {{ HOSTNAME_CFG01 }}
214 retry: {count: 1, delay: 5}
215 skip_fail: false
216
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +0200217- description: Configure salt.minion on all nodes
218 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
219 -C 'I@linux:system' state.sls salt.minion
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +0300220 node_name: {{ HOSTNAME_CFG01 }}
221 retry: {count: 2, delay: 5}
222 skip_fail: false
223
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +0200224- description: Configure ntp and rsyslog on nodes
225 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
226 -C 'I@linux:system' state.sls ntp,rsyslog
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200227 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +0200228 retry: {count: 2, delay: 10}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200229 skip_fail: false
230
231- description: Check salt minion versions on slaves
232 cmd: salt '*' test.version
233 node_name: {{ HOSTNAME_CFG01 }}
234 retry: {count: 1, delay: 5}
235 skip_fail: false
236
237- description: Check salt top states on nodes
238 cmd: salt '*' state.show_top
239 node_name: {{ HOSTNAME_CFG01 }}
240 retry: {count: 1, delay: 5}
241 skip_fail: false