blob: f5c55df18370b96d910e94342461f05602272a42 [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') %}
5{% set SALT_MODELS_BRANCH = os_env('SALT_MODELS_BRANCH','master') %}
6{% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %}
7
8# Address pools for reclass cluster model are taken in the following order:
9# 1. environment variables,
10# 2. config.underlay.address_pools based on fuel-devops address pools
11# (see generated '.ini' file after underlay is created),
12# 3. defaults
13{% set address_pools = config.underlay.address_pools %}
14{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '172.16.10.0/24')) %}
15{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '192.168.10.0/24')) %}
16
17{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
18{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
19
20# Install salt to the config node
21- description: Installing salt master on cfg01
22 cmd: apt-get install -y reclass git; apt-get install -y salt-master
23 node_name: {{ HOSTNAME_CFG01 }}
24 retry: {count: 1, delay: 1}
25 skip_fail: false
26
27- description: Configure salt-master on cfg01
28 cmd: |
29 cat << 'EOF' >> /etc/salt/master.d/master.conf
30 file_roots:
31 base:
32 - /usr/share/salt-formulas/env
33 pillar_opts: False
34 open_mode: True
35 reclass: &reclass
36 storage_type: yaml_fs
37 inventory_base_uri: /srv/salt/reclass
38 ext_pillar:
39 - reclass: *reclass
40 master_tops:
41 reclass: *reclass
42 EOF
43 node_name: {{ HOSTNAME_CFG01 }}
44 retry: {count: 1, delay: 1}
45 skip_fail: false
46
47- description: Configure GIT settings and certificates
48 cmd: touch /root/.git_trusted_certs.pem;
49 for server in github.com; do
50 openssl s_client -showcerts -connect $server:443 </dev/null
51 | openssl x509 -outform PEM
52 >> /root/.git_trusted_certs.pem;
53 done;
54 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
55 HOME=/root git config --global user.email "tcp-qa@example.com";
56 HOME=/root git config --global user.name "TCP QA";
57 node_name: {{ HOSTNAME_CFG01 }}
58 retry: {count: 1, delay: 1}
59 skip_fail: false
60
61- description: Clone reclass models with submodules
62 cmd: |
63 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
64 git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
65 pushd /srv/salt/reclass && git checkout {{ SALT_MODELS_COMMIT }} && popd
66 mkdir -p /srv/salt/reclass/classes/service;
67
68 # Replace firstly to an intermediate value to avoid intersection between
69 # already replaced and replacing networks.
70 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
71 # 192.168.10 -> 10.16.0 (generated network for admin)
72 # 10.16.0 -> <external network>
73 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
74 find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
75 find /srv/salt/reclass/ -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
76
77 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
78 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
79
80 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
81
82 # Disable checkouting the model from remote repository
83 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
84 # local storage
85 reclass:
86 storage:
87 data_source:
88 engine: local
89 EOF
90
91 # Show the changes to the console
92 cd /srv/salt/reclass/; git diff
93 node_name: {{ HOSTNAME_CFG01 }}
94 retry: {count: 1, delay: 1}
95 skip_fail: false
96
97
98- description: Configure reclass
99 cmd: |
100 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
101 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
102 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
103 which wget > /dev/null || (apt-get update; apt-get install -y wget);
104 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
105 wget -O - "${FORMULA_GPG}" | apt-key add -;
106 apt-get clean; apt-get update;
107 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
108 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf");
109 echo -e "\nInstalling all required salt formulas\n";
110 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
111 for formula_service in "${formula_services[@]}"; do
112 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
113 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
114 done;
115 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
116 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
117 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
118
119 cat << 'EOF' >> /etc/reclass/reclass-config.yml
120 storage_type: yaml_fs
121 pretty_print: True
122 output: yaml
123 inventory_base_uri: /srv/salt/reclass
124 EOF
125 node_name: {{ HOSTNAME_CFG01 }}
126 retry: {count: 1, delay: 1}
127 skip_fail: false
128
129- description: Restart salt-master service
130 cmd: |
131 systemctl restart salt-master;
132 node_name: {{ HOSTNAME_CFG01 }}
133 retry: {count: 1, delay: 5}
134 skip_fail: false
135
136{% for ssh in config.underlay.ssh %}
137- description: Configure salt-minion on {{ ssh['node_name'] }}
138 cmd: |
139 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
140 cat << "EOF" >> /etc/salt/minion.d/minion.conf
141 id: {{ ssh['node_name'] }}
142 master: {{ config.salt.salt_master_host }}
143 EOF
144 eatmydata apt-get install -y salt-minion;
145 echo "Check for system info and metadata availability ...";
146 salt-call --no-color grains.items;
147 salt-call --no-color pillar.items;
148 node_name: {{ ssh['node_name'] }}
149 retry: {count: 1, delay: 1}
150 skip_fail: false
151{% endfor %}
152
153- description: Accept salt keys from all the nodes
154 cmd: salt-key -A -y
155 node_name: {{ HOSTNAME_CFG01 }}
156 retry: {count: 1, delay: 5}
157 skip_fail: true
158
159- description: Configure salt adoptors on cfg01
160 cmd: |
161 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
162 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
163 node_name: {{ HOSTNAME_CFG01 }}
164 retry: {count: 1, delay: 1}
165 skip_fail: false
166
Artem Panchenko501e67e2017-06-14 14:59:18 +0300167# Patch linux formula to workaround https://mirantis.jira.com/browse/PROD-12327
168- description:
169 cmd: salt '*' cmd.run 'wget https://raw.githubusercontent.com/saltstack/salt/2017.7/salt/templates/debian_ip/route_eth.jinja -O
170 /usr/lib/python2.7/dist-packages/salt/templates/debian_ip/route_eth.jinja'
171 node_name: {{ HOSTNAME_CFG01 }}
172 retry: {count: 1, delay: 5}
173 skip_fail: false
174
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300175# Prepare salt services and nodes settings
176- description: Run 'linux' formula on cfg01
177 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
178 -C 'I@salt:master' state.sls linux;
179 node_name: {{ HOSTNAME_CFG01 }}
180 retry: {count: 1, delay: 5}
181 skip_fail: false
182
183- description: Run 'openssh' formula on cfg01
184 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
185 -C 'I@salt:master' state.sls openssh;
186 salt --hard-crash --state-output=mixed --state-verbose=False
187 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
188 yes/' /etc/ssh/sshd_config && service ssh restart";
189 node_name: {{ HOSTNAME_CFG01 }}
190 retry: {count: 3, delay: 5}
191 skip_fail: false
192
193- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
194 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
195 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
196 node_name: {{ HOSTNAME_CFG01 }}
197 retry: {count: 1, delay: 1}
198 skip_fail: false
199
200- description: Run 'salt.master' formula on cfg01
201 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
202 -C 'I@salt:master' state.sls salt.master.service;
203 node_name: {{ HOSTNAME_CFG01 }}
204 retry: {count: 2, delay: 5}
205 skip_fail: false
206
207- description: Run 'salt' formula on cfg01 with workaround proposed in PROD-10894
208 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
209 -C 'I@salt:master' state.sls salt;
210 salt --hard-crash --state-output=mixed --state-verbose=False
211 -C 'I@salt:master' saltutil.sync_all
212 node_name: {{ HOSTNAME_CFG01 }}
213 retry: {count: 5, delay: 5}
214 skip_fail: false
215
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300216- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
217 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
218 -C 'I@salt:master' state.sls reclass
219 node_name: {{ HOSTNAME_CFG01 }}
220 retry: {count: 1, delay: 5}
221 skip_fail: false
222
223- description: Refresh pillars on all minions
224 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
225 node_name: {{ HOSTNAME_CFG01 }}
226 retry: {count: 1, delay: 5}
227 skip_fail: false
228
229- description: Sync all salt resources
230 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
231 node_name: {{ HOSTNAME_CFG01 }}
232 retry: {count: 1, delay: 5}
233 skip_fail: false
234
235- description: Show reclass-salt --top
236 cmd: reclass-salt --top
237 node_name: {{ HOSTNAME_CFG01 }}
238 retry: {count: 1, delay: 5}
239 skip_fail: false
240
241- description: Execute salt.minion.cert
242 cmd: salt-call --no-color state.sls salt.minion.cert -l info;
243 node_name: {{ HOSTNAME_CFG01 }}
244 retry: {count: 1, delay: 5}
245 skip_fail: false
246
247# Bootstrap all nodes
248
249- description: Configure linux on other nodes
250 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
251 cfg01*' state.sls linux
252 node_name: {{ HOSTNAME_CFG01 }}
253 retry: {count: 1, delay: 5}
254 skip_fail: false
255
256- description: Configure openssh on all nodes
257 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
258 cfg01*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
259 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
260 yes/' /etc/ssh/sshd_config && service ssh restart"
261 node_name: {{ HOSTNAME_CFG01 }}
262 retry: {count: 1, delay: 5}
263 skip_fail: false
264
265- description: Configure salt.minion on other nodes
266 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
267 cfg01*' state.sls salt.minion
268 node_name: {{ HOSTNAME_CFG01 }}
269 retry: {count: 3, delay: 5}
270 skip_fail: false
271
272- description: Check salt minion versions on slaves
273 cmd: salt '*' test.version
274 node_name: {{ HOSTNAME_CFG01 }}
275 retry: {count: 1, delay: 5}
276 skip_fail: false
277
278- description: Check salt top states on nodes
279 cmd: salt '*' state.show_top
280 node_name: {{ HOSTNAME_CFG01 }}
281 retry: {count: 1, delay: 5}
282 skip_fail: false
283
284- description: Configure ntp and rsyslog on nodes
285 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog
286 node_name: {{ HOSTNAME_CFG01 }}
287 retry: {count: 1, delay: 10}
288 skip_fail: false