blob: ccb40bd3554f2e3c9e726d985f1549b2ba31aa97 [file] [log] [blame]
Dennis Dmitrievab83ea42017-05-12 16:52:45 +03001{% from 'virtual-mcp-ocata-dvr/underlay.yaml' import HOSTNAME_CFG01 with context %}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +03002{% from 'virtual-mcp-ocata-dvr/underlay.yaml' import REPOSITORY_SUITE with context %}
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +03003
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') %}
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +03006{% 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]) %}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030023
24# Install salt to the config node
25
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030026#- 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
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030040
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030041#- 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
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030046
47- description: Installing salt master on cfg01
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030048 cmd: eatmydata apt-get install -y reclass git salt-master
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030049 node_name: {{ HOSTNAME_CFG01 }}
50 retry: {count: 1, delay: 1}
51 skip_fail: false
52
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030053- description: Configure salt-master on cfg01
54 cmd: |
55 cat << 'EOF' >> /etc/salt/master.d/master.conf
56 file_roots:
57 base:
58 - /usr/share/salt-formulas/env
59 pillar_opts: False
60 open_mode: True
61 reclass: &reclass
62 storage_type: yaml_fs
63 inventory_base_uri: /srv/salt/reclass
64 ext_pillar:
65 - reclass: *reclass
66 master_tops:
67 reclass: *reclass
68 EOF
69 node_name: {{ HOSTNAME_CFG01 }}
70 retry: {count: 1, delay: 1}
71 skip_fail: false
72
73- description: Configure GIT settings and certificates
74 cmd: touch /root/.git_trusted_certs.pem;
75 for server in git.tcpcloud.eu github.com; do
76 openssl s_client -showcerts -connect $server:443 </dev/null
77 | openssl x509 -outform PEM
78 >> /root/.git_trusted_certs.pem;
79 done;
80 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
81 HOME=/root git config --global user.email "tcp-qa@example.com";
82 HOME=/root git config --global user.name "TCP QA";
83 node_name: {{ HOSTNAME_CFG01 }}
84 retry: {count: 1, delay: 1}
85 skip_fail: false
86
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030087- description: Clone reclass models with submodules
88 cmd: |
89 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Valentyn Yakovlev08acf9f2017-06-07 14:02:36 +030090 git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
91 pushd /srv/salt/reclass && git checkout {{ SALT_MODELS_COMMIT }} && popd;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030092
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030093 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030094
95 # Replace firstly to an intermediate value to avoid intersection between
96 # already replaced and replacing networks.
97 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
98 # 192.168.10 -> 10.16.0 (generated network for admin)
99 # 10.16.0 -> <external network>
100 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
101 find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
102 find /srv/salt/reclass/ -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
103 find /srv/salt/reclass/ -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} +
104 find /srv/salt/reclass/ -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
105
106 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
107 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
108 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} +
109 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {} +
110
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300111 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
112
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300113 # Disable checkouting the model from remote repository
114 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
115 # local storage
116 reclass:
117 storage:
118 data_source:
119 engine: local
120 EOF
121
122 # Show the changes to the console
123 cd /srv/salt/reclass/; git diff
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300124 node_name: {{ HOSTNAME_CFG01 }}
125 retry: {count: 1, delay: 1}
126 skip_fail: false
127
128- description: Configure reclass
129 cmd: |
130 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Tatyana Leontovicheed70d72017-05-25 16:32:17 +0300131 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
Tatyana Leontovich3c6aa452017-04-25 15:04:40 +0300132 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300133 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Tatyana Leontovich543afa92017-04-21 14:48:03 +0300134 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300135 wget -O - "${FORMULA_GPG}" | apt-key add -;
136 apt-get clean; apt-get update;
137 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich644446f2017-06-08 13:43:36 +0300138 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch");
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300139 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300140 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300141 for formula_service in "${formula_services[@]}"; do
142 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
143 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
144 done;
145 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
146 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
147 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
148
149 cat << 'EOF' >> /etc/reclass/reclass-config.yml
150 storage_type: yaml_fs
151 pretty_print: True
152 output: yaml
153 inventory_base_uri: /srv/salt/reclass
154 EOF
155 node_name: {{ HOSTNAME_CFG01 }}
156 retry: {count: 1, delay: 1}
157 skip_fail: false
158
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300159- description: Restart salt-master service
160 cmd: |
161 systemctl restart salt-master;
162 node_name: {{ HOSTNAME_CFG01 }}
163 retry: {count: 1, delay: 5}
164 skip_fail: false
165
166{% for ssh in config.underlay.ssh %}
167- description: Configure salt-minion on {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300168 cmd: |
169 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
170 cat << "EOF" >> /etc/salt/minion.d/minion.conf
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300171 id: {{ ssh['node_name'] }}
172 master: {{ config.salt.salt_master_host }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300173 EOF
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300174 eatmydata apt-get install -y salt-minion;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300175 echo "Check for system info and metadata availability ...";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300176 salt-call --no-color grains.items;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300177 salt-call --no-color pillar.items;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300178 node_name: {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300179 retry: {count: 1, delay: 1}
180 skip_fail: false
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300181{% endfor %}
182
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300183- description: Accept salt keys from all the nodes
184 cmd: salt-key -A -y
185 node_name: {{ HOSTNAME_CFG01 }}
186 retry: {count: 1, delay: 5}
187 skip_fail: true
188
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300189- description: Configure salt adoptors on cfg01
190 cmd: |
191 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
192 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
193 node_name: {{ HOSTNAME_CFG01 }}
194 retry: {count: 1, delay: 1}
195 skip_fail: false
196
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300197# Prepare salt services and nodes settings
198- description: Run 'linux' formula on cfg01
Tatyana Leontovich18013122017-06-09 20:24:50 +0300199 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300200 node_name: {{ HOSTNAME_CFG01 }}
201 retry: {count: 1, delay: 5}
202 skip_fail: false
203
204- description: Run 'openssh' formula on cfg01
205 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
206 -C 'I@salt:master' state.sls openssh;
207 salt --hard-crash --state-output=mixed --state-verbose=False
208 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Tatyana Leontovich18013122017-06-09 20:24:50 +0300209 yes/' /etc/ssh/sshd_config && service ssh reload";
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300210 node_name: {{ HOSTNAME_CFG01 }}
211 retry: {count: 3, delay: 5}
212 skip_fail: false
213
214- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
215 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
216 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
217 node_name: {{ HOSTNAME_CFG01 }}
218 retry: {count: 1, delay: 1}
219 skip_fail: false
220
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300221- description: Run 'salt.master' formula on cfg01
Tatyana Leontovich18013122017-06-09 20:24:50 +0300222 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300223 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300224 retry: {count: 2, delay: 5}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300225 skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300226
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300227- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
228 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
229 -C 'I@salt:master' state.sls reclass
230 node_name: {{ HOSTNAME_CFG01 }}
231 retry: {count: 1, delay: 5}
232 skip_fail: false
233
234- description: Refresh pillars on all minions
235 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
236 node_name: {{ HOSTNAME_CFG01 }}
237 retry: {count: 1, delay: 5}
238 skip_fail: false
239
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300240- description: Show reclass-salt --top
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300241 cmd: reclass-salt --top
242 node_name: {{ HOSTNAME_CFG01 }}
243 retry: {count: 1, delay: 5}
244 skip_fail: false
245
Tatyana Leontovich18013122017-06-09 20:24:50 +0300246- description: Sync all salt resources
247 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300248 node_name: {{ HOSTNAME_CFG01 }}
249 retry: {count: 1, delay: 5}
250 skip_fail: false
251
Tatyana Leontovich18013122017-06-09 20:24:50 +0300252- description: Configure linux on master
253 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
254 node_name: {{ HOSTNAME_CFG01 }}
255 retry: {count: 1, delay: 5}
256 skip_fail: false
257
258- description: Configure minion on master
259 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
260 -C 'I@salt:master' state.sls 'salt.minion'
261 node_name: {{ HOSTNAME_CFG01 }}
262 retry: {count: 3, delay: 10}
263 skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300264
265# Bootstrap all nodes
266
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300267- description: Configure linux on other nodes
Tatyana Leontovich18013122017-06-09 20:24:50 +0300268 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls 'linux'
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300269 node_name: {{ HOSTNAME_CFG01 }}
270 retry: {count: 1, delay: 5}
271 skip_fail: false
272
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300273- description: Configure openssh on all nodes
Tatyana Leontovich18013122017-06-09 20:24:50 +0300274 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls openssh;
275 salt --hard-crash --state-output=mixed --state-verbose=False
276 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
277 yes/' /etc/ssh/sshd_config && service ssh reload"
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300278 node_name: {{ HOSTNAME_CFG01 }}
279 retry: {count: 1, delay: 5}
280 skip_fail: false
281
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300282- description: Configure salt.minion on other nodes
Tatyana Leontovich18013122017-06-09 20:24:50 +0300283 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300284 node_name: {{ HOSTNAME_CFG01 }}
285 retry: {count: 3, delay: 5}
286 skip_fail: false
287
288- description: Check salt minion versions on slaves
289 cmd: salt '*' test.version
290 node_name: {{ HOSTNAME_CFG01 }}
291 retry: {count: 1, delay: 5}
292 skip_fail: false
293
294- description: Check salt top states on nodes
295 cmd: salt '*' state.show_top
296 node_name: {{ HOSTNAME_CFG01 }}
297 retry: {count: 1, delay: 5}
298 skip_fail: false
299
300- description: Configure ntp and rsyslog on nodes
Tatyana Leontovich18013122017-06-09 20:24:50 +0300301 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300302 node_name: {{ HOSTNAME_CFG01 }}
303 retry: {count: 1, delay: 10}
304 skip_fail: false
305
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300306- description: Hack gtw node
307 cmd: salt 'gtw*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4";
308 node_name: {{ HOSTNAME_CFG01 }}
309 retry: {count: 1, delay: 10}
310 skip_fail: false
311
312- description: Hack cmp01 node
313 cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
314 node_name: {{ HOSTNAME_CFG01 }}
315 retry: {count: 1, delay: 10}
316 skip_fail: false
317
318- description: Hack cmp02 node
319 cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
320 node_name: {{ HOSTNAME_CFG01 }}
321 retry: {count: 1, delay: 10}
322 skip_fail: false