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