blob: 36bcb2a428c74f36e1222de9abbe6cf635c912c4 [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') %}
5{% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %}
6
7# Address pools for reclass cluster model are taken in the following order:
8# 1. environment variables,
9# 2. config.underlay.address_pools based on fuel-devops address pools
10# (see generated '.ini' file after underlay is created),
11# 3. defaults
12{% set address_pools = config.underlay.address_pools %}
13{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '172.16.10.0/24')) %}
14{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '192.168.10.0/24')) %}
15
16{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
17{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020018
19# Install salt to the config node
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020020- description: Installing salt master on cfg01
21 cmd: apt-get install -y reclass git; apt-get install -y salt-master
22 node_name: {{ HOSTNAME_CFG01 }}
23 retry: {count: 1, delay: 1}
24 skip_fail: false
25
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020026- description: Configure salt-master on cfg01
27 cmd: |
28 cat << 'EOF' >> /etc/salt/master.d/master.conf
29 file_roots:
30 base:
31 - /usr/share/salt-formulas/env
32 pillar_opts: False
33 open_mode: True
34 reclass: &reclass
35 storage_type: yaml_fs
36 inventory_base_uri: /srv/salt/reclass
37 ext_pillar:
38 - reclass: *reclass
39 master_tops:
40 reclass: *reclass
41 EOF
42 node_name: {{ HOSTNAME_CFG01 }}
43 retry: {count: 1, delay: 1}
44 skip_fail: false
45
46- description: Configure GIT settings and certificates
47 cmd: touch /root/.git_trusted_certs.pem;
Matthew Mosesohnd0632b82017-05-30 17:51:30 +030048 for server in github.com; do
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020049 openssl s_client -showcerts -connect $server:443 </dev/null
50 | openssl x509 -outform PEM
51 >> /root/.git_trusted_certs.pem;
52 done;
53 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
54 HOME=/root git config --global user.email "tcp-qa@example.com";
55 HOME=/root git config --global user.name "TCP QA";
56 node_name: {{ HOSTNAME_CFG01 }}
57 retry: {count: 1, delay: 1}
58 skip_fail: false
59
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020060- description: Clone reclass models with submodules
Tatyana Leontovichcf37cb22017-05-19 14:59:38 +030061 cmd: |
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020062 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Tatyana Leontovich573584a2017-05-19 14:54:00 +030063 git clone -b {{ SALT_MODELS_COMMIT }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020064 mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030065
66 # Replace firstly to an intermediate value to avoid intersection between
67 # already replaced and replacing networks.
68 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
69 # 192.168.10 -> 10.16.0 (generated network for admin)
70 # 10.16.0 -> <external network>
71 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Tatyana Leontovich573584a2017-05-19 14:54:00 +030072 find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
73 find /srv/salt/reclass/ -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030074
75 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
76 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
77
78 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
79
80 # Disable checkouting the model from remote repository
81 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
82 # local storage
83 reclass:
84 storage:
85 data_source:
86 engine: local
87 EOF
Tatyana Leontovichcf37cb22017-05-19 14:59:38 +030088
89 # Show the changes to the console
90 cd /srv/salt/reclass/; git diff
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020091 node_name: {{ HOSTNAME_CFG01 }}
92 retry: {count: 1, delay: 1}
93 skip_fail: false
94
Tatyana Leontovichcf37cb22017-05-19 14:59:38 +030095
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020096- description: Configure reclass
97 cmd: |
98 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Tatyana Leontovich5fbd0382017-05-19 19:41:24 +030099 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200100 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
101 which wget > /dev/null || (apt-get update; apt-get install -y wget);
102 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
103 wget -O - "${FORMULA_GPG}" | apt-key add -;
104 apt-get clean; apt-get update;
105 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich9ce755b2017-05-19 16:24:32 +0300106 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf");
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200107 echo -e "\nInstalling all required salt formulas\n";
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300108 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200109 for formula_service in "${formula_services[@]}"; do
110 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
111 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
112 done;
113 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
114 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
115 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
116
117 cat << 'EOF' >> /etc/reclass/reclass-config.yml
118 storage_type: yaml_fs
119 pretty_print: True
120 output: yaml
121 inventory_base_uri: /srv/salt/reclass
122 EOF
123 node_name: {{ HOSTNAME_CFG01 }}
124 retry: {count: 1, delay: 1}
125 skip_fail: false
126
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300127- description: Restart salt-master service
128 cmd: |
129 systemctl restart salt-master;
130 node_name: {{ HOSTNAME_CFG01 }}
131 retry: {count: 1, delay: 5}
132 skip_fail: false
133
134{% for ssh in config.underlay.ssh %}
135- description: Configure salt-minion on {{ ssh['node_name'] }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200136 cmd: |
137 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
138 cat << "EOF" >> /etc/salt/minion.d/minion.conf
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300139 id: {{ ssh['node_name'] }}
140 master: {{ config.salt.salt_master_host }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200141 EOF
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300142 eatmydata apt-get install -y salt-minion;
143 echo "Check for system info and metadata availability ...";
144 salt-call --no-color grains.items;
145 salt-call --no-color pillar.items;
146 node_name: {{ ssh['node_name'] }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200147 retry: {count: 1, delay: 1}
148 skip_fail: false
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300149{% endfor %}
150
151- description: Accept salt keys from all the nodes
152 cmd: salt-key -A -y
153 node_name: {{ HOSTNAME_CFG01 }}
154 retry: {count: 1, delay: 5}
155 skip_fail: true
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200156
157- description: Configure salt adoptors on cfg01
158 cmd: |
159 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
160 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
161 node_name: {{ HOSTNAME_CFG01 }}
162 retry: {count: 1, delay: 1}
163 skip_fail: false
164
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200165# Prepare salt services and nodes settings
166- description: Run 'linux' formula on cfg01
167 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
168 -C 'I@salt:master' state.sls linux;
169 node_name: {{ HOSTNAME_CFG01 }}
170 retry: {count: 1, delay: 5}
171 skip_fail: false
172
173- description: Run 'openssh' formula on cfg01
174 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
175 -C 'I@salt:master' state.sls openssh;
176 salt --hard-crash --state-output=mixed --state-verbose=False
177 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
178 yes/' /etc/ssh/sshd_config && service ssh restart";
179 node_name: {{ HOSTNAME_CFG01 }}
180 retry: {count: 3, delay: 5}
181 skip_fail: false
182
183- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
184 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
185 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
186 node_name: {{ HOSTNAME_CFG01 }}
187 retry: {count: 1, delay: 1}
188 skip_fail: false
189
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300190- description: Run 'salt.master' formula on cfg01
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200191 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
192 -C 'I@salt:master' state.sls salt.master.service;
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200193 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300194 retry: {count: 2, delay: 5}
195 skip_fail: false
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200196
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300197- description: Run 'salt' formula on cfg01 with workaround proposed in PROD-10894
198 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
199 -C 'I@salt:master' state.sls salt;
200 salt --hard-crash --state-output=mixed --state-verbose=False
201 -C 'I@salt:master' saltutil.sync_all
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200202 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300203 retry: {count: 5, delay: 5}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200204 skip_fail: false
205
206- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
207 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
208 -C 'I@salt:master' state.sls reclass
209 node_name: {{ HOSTNAME_CFG01 }}
210 retry: {count: 1, delay: 5}
211 skip_fail: false
212
213- description: Refresh pillars on all minions
214 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
215 node_name: {{ HOSTNAME_CFG01 }}
216 retry: {count: 1, delay: 5}
217 skip_fail: false
218
219- description: Sync all salt resources
220 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
221 node_name: {{ HOSTNAME_CFG01 }}
222 retry: {count: 1, delay: 5}
223 skip_fail: false
224
Sergii Golovatiuk5b659d42017-05-26 17:38:06 +0200225- description: Show reclass-salt --top
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300226 cmd: reclass-salt --top
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200227 node_name: {{ HOSTNAME_CFG01 }}
228 retry: {count: 1, delay: 5}
229 skip_fail: false
230
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300231- description: Execute salt.minion.cert
232 cmd: salt-call --no-color state.sls salt.minion.cert -l info;
233 node_name: {{ HOSTNAME_CFG01 }}
234 retry: {count: 1, delay: 5}
235 skip_fail: false
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200236
237# Bootstrap all nodes
238
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300239- description: Configure linux on other nodes
240 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +0300241 cfg01* and not mon*' state.sls linux
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200242 node_name: {{ HOSTNAME_CFG01 }}
243 retry: {count: 1, delay: 5}
244 skip_fail: false
245
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +0300246- description: Configure linux on mon nodes
247 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'mon*' state.sls linux
248 node_name: {{ HOSTNAME_CFG01 }}
249 retry: {count: 2, delay: 5}
250 skip_fail: false
251
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200252- description: Configure openssh on all nodes
253 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300254 cfg01*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200255 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
256 yes/' /etc/ssh/sshd_config && service ssh restart"
257 node_name: {{ HOSTNAME_CFG01 }}
258 retry: {count: 1, delay: 5}
259 skip_fail: false
260
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300261- description: Configure salt.minion on other nodes
262 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
263 cfg01*' state.sls salt.minion
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200264 node_name: {{ HOSTNAME_CFG01 }}
265 retry: {count: 3, delay: 5}
266 skip_fail: false
267
268- description: Check salt minion versions on slaves
269 cmd: salt '*' test.version
270 node_name: {{ HOSTNAME_CFG01 }}
271 retry: {count: 1, delay: 5}
272 skip_fail: false
273
274- description: Check salt top states on nodes
275 cmd: salt '*' state.show_top
276 node_name: {{ HOSTNAME_CFG01 }}
277 retry: {count: 1, delay: 5}
278 skip_fail: false
279
280- description: Configure ntp and rsyslog on nodes
281 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog
282 node_name: {{ HOSTNAME_CFG01 }}
283 retry: {count: 1, delay: 10}
284 skip_fail: false