blob: e3a253773f2974b6ac9ea38474877049fbebdb40 [file] [log] [blame]
Artem Panchenkoedf70ef2017-06-13 09:14:34 +03001{% from 'virtual-mcp11-k8s-calico-minimal/underlay.yaml' import HOSTNAME_CFG01 with context %}
2{% from 'virtual-mcp11-k8s-calico-minimal/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
Artem Panchenkoedf70ef2017-06-13 09:14:34 +03006
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02007{% import 'shared-salt.yaml' as SHARED with context %}
Artem Panchenkoedf70ef2017-06-13 09:14:34 +03008
9# Install salt to the config node
10- 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
16- 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;
38 for server in github.com; do
39 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
50- description: Clone reclass models with submodules
51 cmd: |
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020052{{ SHARED.MACRO_CLONE_RECLASS_MODELS() }}
Artem Panchenkoedf70ef2017-06-13 09:14:34 +030053 # Show the changes to the console
54 cd /srv/salt/reclass/; git diff
55 node_name: {{ HOSTNAME_CFG01 }}
56 retry: {count: 1, delay: 1}
57 skip_fail: false
58
Artem Panchenkoedf70ef2017-06-13 09:14:34 +030059- 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};
Artem Panchenkoedf70ef2017-06-13 09:14:34 +030064 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;
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +020069 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch");
Artem Panchenkoedf70ef2017-06-13 09:14:34 +030070 echo -e "\nInstalling all required salt formulas\n";
71 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
72 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
90- 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'] }}
99 cmd: |
100 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
101 cat << "EOF" >> /etc/salt/minion.d/minion.conf
102 id: {{ ssh['node_name'] }}
103 master: {{ config.salt.salt_master_host }}
104 EOF
105 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;
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300109 node_name: {{ ssh['node_name'] }}
110 retry: {count: 1, delay: 1}
111 skip_fail: false
112{% 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
119
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
128# 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}
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300134 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
153- 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;
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300156 node_name: {{ HOSTNAME_CFG01 }}
157 retry: {count: 2, delay: 5}
158 skip_fail: false
159
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300160- 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
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300173- description: Show reclass-salt --top
174 cmd: reclass-salt --top
175 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
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300181 node_name: {{ HOSTNAME_CFG01 }}
182 retry: {count: 1, delay: 5}
183 skip_fail: false
184
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
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300198# Bootstrap all nodes
199
200- 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'
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300203 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +0200204 retry: {count: 3, delay: 5}
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300205 skip_fail: false
206
207- description: Configure openssh on all nodes
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +0200208 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"
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300213 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
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300220 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +0200221 retry: {count: 2, delay: 5}
222 skip_fail: false
223
224- 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
227 node_name: {{ HOSTNAME_CFG01 }}
228 retry: {count: 2, delay: 10}
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300229 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