blob: d9011bbb9925fa6d916ff86767e31ebb78492f92 [file] [log] [blame]
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +03001{% from 'virtual-mcp11-k8s-contrail/underlay.yaml' import HOSTNAME_CFG01 with context %}
2{% from 'virtual-mcp11-k8s-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') %}
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 %}
Sergii Golovatiukf03899c2017-05-30 12:12:00 +020013{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('public-pool01', '192.168.10.0/24')) %}
14{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030015
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]) %}
18
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +030019# Install salt to the config node
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030020- description: Installing salt master on cfg01
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +030021 cmd: apt-get install -y reclass git; apt-get install -y salt-master
Sergii Golovatiukc504a392017-05-22 21:41:06 +020022 node_name: {{ HOSTNAME_CFG01 }}
23 retry: {count: 1, delay: 1}
24 skip_fail: false
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030025
26- 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
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030049 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
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030060- description: Clone reclass models with submodules
61 cmd: |
62 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
63 git clone -b {{ SALT_MODELS_COMMIT }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030064 mkdir -p /srv/salt/reclass/classes/service;
Sergii Golovatiukf03899c2017-05-30 12:12:00 +020065
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.
72 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' {} +
74
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 find /srv/salt/reclass/ -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
80
81 # Disable checkouting the model from remote repository
82 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
83 # local storage
84 reclass:
85 storage:
86 data_source:
87 engine: local
88 EOF
89
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030090 node_name: {{ HOSTNAME_CFG01 }}
91 retry: {count: 1, delay: 1}
92 skip_fail: false
93
94- description: Configure reclass
95 cmd: |
96 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Tatyana Leontovicheed70d72017-05-25 16:32:17 +030097 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030098 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
99 which wget > /dev/null || (apt-get update; apt-get install -y wget);
100 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
101 wget -O - "${FORMULA_GPG}" | apt-key add -;
102 apt-get clean; apt-get update;
103 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovicheed70d72017-05-25 16:32:17 +0300104 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf");
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300105 echo -e "\nInstalling all required salt formulas\n";
106 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
107 for formula_service in "${formula_services[@]}"; do
108 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
109 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
110 done;
111 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
112 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
113 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
114
115 cat << 'EOF' >> /etc/reclass/reclass-config.yml
116 storage_type: yaml_fs
117 pretty_print: True
118 output: yaml
119 inventory_base_uri: /srv/salt/reclass
120 EOF
121 node_name: {{ HOSTNAME_CFG01 }}
122 retry: {count: 1, delay: 1}
123 skip_fail: false
124
125- description: Restart salt-master service
126 cmd: |
127 systemctl restart salt-master;
128 node_name: {{ HOSTNAME_CFG01 }}
129 retry: {count: 1, delay: 5}
130 skip_fail: false
131
132{% for ssh in config.underlay.ssh %}
133- description: Configure salt-minion on {{ ssh['node_name'] }}
134 cmd: |
135 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
136 cat << "EOF" >> /etc/salt/minion.d/minion.conf
137 id: {{ ssh['node_name'] }}
138 master: {{ config.salt.salt_master_host }}
139 EOF
140 eatmydata apt-get install -y salt-minion;
141 echo "Check for system info and metadata availability ...";
142 salt-call --no-color grains.items;
143 salt-call --no-color pillar.items;
144 node_name: {{ ssh['node_name'] }}
145 retry: {count: 1, delay: 1}
146 skip_fail: false
147{% endfor %}
148
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300149- description: Accept salt keys from all the nodes
150 cmd: salt-key -A -y
151 node_name: {{ HOSTNAME_CFG01 }}
152 retry: {count: 1, delay: 5}
153 skip_fail: true
154
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300155- description: Configure salt adoptors on cfg01
156 cmd: |
157 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
158 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
159 node_name: {{ HOSTNAME_CFG01 }}
160 retry: {count: 1, delay: 1}
161 skip_fail: false
162
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300163# Prepare salt services and nodes settings
164- description: Run 'linux' formula on cfg01
165 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
166 -C 'I@salt:master' state.sls linux;
167 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk17ef1492017-05-29 19:54:03 +0200168 retry: {count: 3, delay: 5}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300169 skip_fail: false
170
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300171- description: Run 'openssh' formula on cfg01
172 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
173 -C 'I@salt:master' state.sls openssh;
174 salt --hard-crash --state-output=mixed --state-verbose=False
175 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
176 yes/' /etc/ssh/sshd_config && service ssh restart";
177 node_name: {{ HOSTNAME_CFG01 }}
178 retry: {count: 3, delay: 5}
179 skip_fail: false
180
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300181- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
182 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
183 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
184 node_name: {{ HOSTNAME_CFG01 }}
185 retry: {count: 1, delay: 1}
186 skip_fail: false
187
188- description: Run 'salt.master' formula on cfg01
189 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
190 -C 'I@salt:master' state.sls salt.master.service;
191 node_name: {{ HOSTNAME_CFG01 }}
192 retry: {count: 2, delay: 5}
193 skip_fail: false
194
195- description: Run 'salt' formula on cfg01 with workaround proposed in PROD-10894
196 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
197 -C 'I@salt:master' state.sls salt;
198 salt --hard-crash --state-output=mixed --state-verbose=False
199 -C 'I@salt:master' saltutil.sync_all
200 node_name: {{ HOSTNAME_CFG01 }}
201 retry: {count: 5, delay: 5}
202 skip_fail: false
203
204- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
205 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
206 -C 'I@salt:master' state.sls reclass
207 node_name: {{ HOSTNAME_CFG01 }}
208 retry: {count: 1, delay: 5}
209 skip_fail: false
210
211- description: Refresh pillars on all minions
212 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
213 node_name: {{ HOSTNAME_CFG01 }}
214 retry: {count: 1, delay: 5}
215 skip_fail: false
216
217- description: Sync all salt resources
218 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
219 node_name: {{ HOSTNAME_CFG01 }}
220 retry: {count: 1, delay: 5}
221 skip_fail: false
222
Sergii Golovatiuk5b659d42017-05-26 17:38:06 +0200223- description: Show reclass-salt --top
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300224 cmd: reclass-salt --top
225 node_name: {{ HOSTNAME_CFG01 }}
226 retry: {count: 1, delay: 5}
227 skip_fail: false
228
229- description: Execute salt.minion.cert
230 cmd: salt-call --no-color state.sls salt.minion.cert -l info;
231 node_name: {{ HOSTNAME_CFG01 }}
232 retry: {count: 1, delay: 5}
233 skip_fail: false
234
235# Bootstrap all nodes
236
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +0300237- description: Configure linux on other nodes
238 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Sergii Golovatiuk5b659d42017-05-26 17:38:06 +0200239 cfg01* and not mon*' state.sls linux
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300240 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk17ef1492017-05-29 19:54:03 +0200241 retry: {count: 3, delay: 5}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300242 skip_fail: false
243
Sergii Golovatiuk5b659d42017-05-26 17:38:06 +0200244- description: Configure linux on mon nodes
245 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'mon*' state.sls linux
246 node_name: {{ HOSTNAME_CFG01 }}
247 retry: {count: 2, delay: 5}
248 skip_fail: false
249
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300250- description: Configure openssh on all nodes
251 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +0300252 cfg01*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300253 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
254 yes/' /etc/ssh/sshd_config && service ssh restart"
255 node_name: {{ HOSTNAME_CFG01 }}
256 retry: {count: 1, delay: 5}
257 skip_fail: false
258
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +0300259- description: Configure salt.minion on other nodes
260 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
261 cfg01*' state.sls salt.minion
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300262 node_name: {{ HOSTNAME_CFG01 }}
263 retry: {count: 3, delay: 5}
264 skip_fail: false
265
266- description: Check salt minion versions on slaves
267 cmd: salt '*' test.version
268 node_name: {{ HOSTNAME_CFG01 }}
269 retry: {count: 1, delay: 5}
270 skip_fail: false
271
272- description: Check salt top states on nodes
273 cmd: salt '*' state.show_top
274 node_name: {{ HOSTNAME_CFG01 }}
275 retry: {count: 1, delay: 5}
276 skip_fail: false
277
278- description: Configure ntp and rsyslog on nodes
279 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog
280 node_name: {{ HOSTNAME_CFG01 }}
281 retry: {count: 1, delay: 10}
282 skip_fail: false