blob: e99b83e9cbe9f695a94057d782bdae86de7daf55 [file] [log] [blame]
Illia Polliul2a2b6d12017-05-29 17:05:11 +02001{% from 'virtual-mcp10-contrail/underlay.yaml' import HOSTNAME_CFG01 with context %}
2{% from 'virtual-mcp10-contrail/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') %}
Valentyn Yakovlev08acf9f2017-06-07 14:02:36 +03005{% set SALT_MODELS_BRANCH = os_env('SALT_MODELS_BRANCH','master') %}
Illia Polliul2a2b6d12017-05-29 17:05:11 +02006{% 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', '192.168.10.0/24')) %}
15{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
16{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
17{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
18
19{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
20{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
21{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
22{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
23
24# Install salt to the config node
25
26#- description: (moved to cloud-init config) Configure repository on the cfg01 node
27# cmd:
28# echo "172.18.248.114 jenkins.mcp.mirantis.net gerrit.mcp.mirantis.net" >> /etc/hosts;
29# echo "185.135.196.10 apt-mk.mirantis.com" >> /etc/hosts;
30# echo "nameserver 172.18.208.44 >> /etc/resolv.conf;
31# echo "nameserver 8.8.8.8 >> /etc/resolv.conf;
32# which wget >/dev/null || (apt-get update; apt-get install -y wget);
33# echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial nightly salt extra" > /etc/apt/sources.list.d/mcp_salt.list;
34# wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -;
35# echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list;
36# wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -;
37# node_name: {{ HOSTNAME_CFG01 }}
38# retry: {count: 1, delay: 1}
39# skip_fail: false
40
41#- description: Update packages on cfg01
42# cmd: apt-get clean; eatmydata apt-get update
43# node_name: {{ HOSTNAME_CFG01 }}
44# retry: {count: 1, delay: 1}
45# skip_fail: false
46
47- description: Installing salt master on cfg01
48 cmd: eatmydata apt-get install -y reclass git salt-master
49 node_name: {{ HOSTNAME_CFG01 }}
50 retry: {count: 1, delay: 1}
51 skip_fail: false
52
53#- description: (moved to cloud-init config) Install common packages on cfg01
54# cmd: eatmydata apt-get install -y python-pip wget curl tmux byobu iputils-ping traceroute htop tree
55# node_name: {{ HOSTNAME_CFG01 }}
56# retry: {count: 1, delay: 1}
57# skip_fail: false
58
59- description: Configure salt-master on cfg01
60 cmd: |
61 cat << 'EOF' >> /etc/salt/master.d/master.conf
62 file_roots:
63 base:
64 - /usr/share/salt-formulas/env
65 pillar_opts: False
66 open_mode: True
67 reclass: &reclass
68 storage_type: yaml_fs
69 inventory_base_uri: /srv/salt/reclass
70 ext_pillar:
71 - reclass: *reclass
72 master_tops:
73 reclass: *reclass
74 EOF
75 node_name: {{ HOSTNAME_CFG01 }}
76 retry: {count: 1, delay: 1}
77 skip_fail: false
78
79- description: Configure GIT settings and certificates
80 cmd: touch /root/.git_trusted_certs.pem;
81 for server in git.tcpcloud.eu github.com; do
82 openssl s_client -showcerts -connect $server:443 </dev/null
83 | openssl x509 -outform PEM
84 >> /root/.git_trusted_certs.pem;
85 done;
86 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
87 HOME=/root git config --global user.email "tcp-qa@example.com";
88 HOME=/root git config --global user.name "TCP QA";
89 node_name: {{ HOSTNAME_CFG01 }}
90 retry: {count: 1, delay: 1}
91 skip_fail: false
92
93
94- description: Clone reclass models with submodules
95 cmd: |
96 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Valentyn Yakovlev08acf9f2017-06-07 14:02:36 +030097 git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
98 pushd /srv/salt/reclass && git checkout {{ SALT_MODELS_COMMIT }} && popd;
Illia Polliul2a2b6d12017-05-29 17:05:11 +020099
100 mkdir -p /srv/salt/reclass/classes/service;
101
102 # Replace firstly to an intermediate value to avoid intersection between
103 # already replaced and replacing networks.
104 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
105 # 192.168.10 -> 10.16.0 (generated network for admin)
106 # 10.16.0 -> <external network>
107 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
108 find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
109 find /srv/salt/reclass/ -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
110 find /srv/salt/reclass/ -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} +
111 find /srv/salt/reclass/ -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
112
113 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
114 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
115 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} +
116 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {} +
117
118 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
119
120 # Disable checkouting the model from remote repository
121 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
122 # local storage
123 reclass:
124 storage:
125 data_source:
126 engine: local
127 EOF
128
129 # Show the changes to the console
130 cd /srv/salt/reclass/; git diff
131 node_name: {{ HOSTNAME_CFG01 }}
132 retry: {count: 1, delay: 1}
133 skip_fail: false
134
135- description: Configure reclass
136 cmd: |
137 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
138 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial stable salt};
139 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
140 which wget > /dev/null || (apt-get update; apt-get install -y wget);
141 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
142 wget -O - "${FORMULA_GPG}" | apt-key add -;
143 apt-get clean; apt-get update;
144 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
145 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon");
146 echo -e "\nInstalling all required salt formulas\n";
147 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
148 for formula_service in "${formula_services[@]}"; do
149 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
150 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
151 done;
152 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
153 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
154 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
155
156 cat << 'EOF' >> /etc/reclass/reclass-config.yml
157 storage_type: yaml_fs
158 pretty_print: True
159 output: yaml
160 inventory_base_uri: /srv/salt/reclass
161 EOF
162 node_name: {{ HOSTNAME_CFG01 }}
163 retry: {count: 1, delay: 1}
164 skip_fail: false
165
166- description: Restart salt-master service
167 cmd: |
168 systemctl restart salt-master;
169 node_name: {{ HOSTNAME_CFG01 }}
170 retry: {count: 1, delay: 5}
171 skip_fail: false
172
173{% for ssh in config.underlay.ssh %}
174- description: Configure salt-minion on {{ ssh['node_name'] }}
175 cmd: |
176 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
177 cat << "EOF" >> /etc/salt/minion.d/minion.conf
178 id: {{ ssh['node_name'] }}
179 master: {{ config.salt.salt_master_host }}
180 EOF
181 eatmydata apt-get install -y salt-minion;
182 echo "Check for system info and metadata availability ...";
183 salt-call --no-color grains.items;
184 salt-call --no-color pillar.items;
185 node_name: {{ ssh['node_name'] }}
186 retry: {count: 1, delay: 1}
187 skip_fail: false
188{% endfor %}
189
190
191- description: Accept salt keys from all the nodes
192 cmd: salt-key -A -y
193 node_name: {{ HOSTNAME_CFG01 }}
194 retry: {count: 1, delay: 5}
195 skip_fail: true
196
197
198- description: Configure salt adoptors on cfg01
199 cmd: |
200 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
201 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
202 node_name: {{ HOSTNAME_CFG01 }}
203 retry: {count: 1, delay: 1}
204 skip_fail: false
205
206
207# Prepare salt services and nodes settings
208- description: Run 'linux' formula on cfg01
209 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
210 -C 'I@salt:master' state.sls linux;
211 node_name: {{ HOSTNAME_CFG01 }}
212 retry: {count: 1, delay: 5}
213 skip_fail: false
214
215
216- description: Run 'openssh' formula on cfg01
217 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
218 -C 'I@salt:master' state.sls openssh;
219 salt --hard-crash --state-output=mixed --state-verbose=False
220 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
221 yes/' /etc/ssh/sshd_config && service ssh restart";
222 node_name: {{ HOSTNAME_CFG01 }}
223 retry: {count: 3, delay: 5}
224 skip_fail: false
225
226
227- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
228 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
229 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
230 node_name: {{ HOSTNAME_CFG01 }}
231 retry: {count: 1, delay: 1}
232 skip_fail: false
233
234- description: Run 'salt.master' formula on cfg01
235 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
236 -C 'I@salt:master' state.sls salt.master.service;
237 node_name: {{ HOSTNAME_CFG01 }}
238 retry: {count: 2, delay: 5}
239 skip_fail: false
240
241- description: Run 'salt' formula on cfg01 with workaround proposed in PROD-10894
242 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
243 -C 'I@salt:master' state.sls salt;
244 salt --hard-crash --state-output=mixed --state-verbose=False
245 -C 'I@salt:master' saltutil.sync_all
246 node_name: {{ HOSTNAME_CFG01 }}
247 retry: {count: 5, delay: 5}
248 skip_fail: false
249
250- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
251 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
252 -C 'I@salt:master' state.sls reclass
253 node_name: {{ HOSTNAME_CFG01 }}
254 retry: {count: 1, delay: 5}
255 skip_fail: false
256
257- description: Refresh pillars on all minions
258 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
259 node_name: {{ HOSTNAME_CFG01 }}
260 retry: {count: 1, delay: 5}
261 skip_fail: false
262
263- description: Sync all salt resources
264 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
265 node_name: {{ HOSTNAME_CFG01 }}
266 retry: {count: 1, delay: 5}
267 skip_fail: false
268
269- description: Show reclass-salt --top
270 cmd: reclass-salt --top
271 node_name: {{ HOSTNAME_CFG01 }}
272 retry: {count: 1, delay: 5}
273 skip_fail: false
274
275- description: Execute salt.minion.cert
276 cmd: salt-call --no-color state.sls salt.minion.cert -l info;
277 node_name: {{ HOSTNAME_CFG01 }}
278 retry: {count: 1, delay: 5}
279 skip_fail: false
280
281
282# Bootstrap all nodes
283
284- description: Configure linux on other nodes
285 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
286 cfg01*' state.sls linux
287 node_name: {{ HOSTNAME_CFG01 }}
288 retry: {count: 1, delay: 5}
289 skip_fail: false
290
291- description: Configure openssh on all nodes
292 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
293 cfg01*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
294 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
295 yes/' /etc/ssh/sshd_config && service ssh restart"
296 node_name: {{ HOSTNAME_CFG01 }}
297 retry: {count: 1, delay: 5}
298 skip_fail: false
299
300- description: Configure salt.minion on other nodes
301 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
302 cfg01*' state.sls salt.minion
303 node_name: {{ HOSTNAME_CFG01 }}
304 retry: {count: 3, delay: 5}
305 skip_fail: false
306
307- description: Check salt minion versions on slaves
308 cmd: salt '*' test.version
309 node_name: {{ HOSTNAME_CFG01 }}
310 retry: {count: 1, delay: 5}
311 skip_fail: false
312
313- description: Check salt top states on nodes
314 cmd: salt '*' state.show_top
315 node_name: {{ HOSTNAME_CFG01 }}
316 retry: {count: 1, delay: 5}
317 skip_fail: false
318
319- description: Configure ntp and rsyslog on nodes
320 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog
321 node_name: {{ HOSTNAME_CFG01 }}
322 retry: {count: 1, delay: 10}
323 skip_fail: false
324
325- description: Hack cmp01 node
326 cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
327 node_name: {{ HOSTNAME_CFG01 }}
328 retry: {count: 1, delay: 10}
329 skip_fail: false
330
331- description: Hack cmp02 node
332 cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
333 node_name: {{ HOSTNAME_CFG01 }}
334 retry: {count: 1, delay: 10}
335 skip_fail: false