blob: b40a2d39ef24d243ddad3779027a8b33fba54657 [file] [log] [blame]
Dennis Dmitrievab83ea42017-05-12 16:52:45 +03001{% from 'virtual-mcp-ocata-ovs/underlay.yaml' import HOSTNAME_CFG01 with context %}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +03002{% from 'virtual-mcp-ocata-ovs/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
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030053#- 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
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +030058
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;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030099
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300100 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300101
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
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300118 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
119
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300120 # 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
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300131 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};
Tatyana Leontovicheed70d72017-05-25 16:32:17 +0300138 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
Tatyana Leontovich3c6aa452017-04-25 15:04:40 +0300139 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300140 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Tatyana Leontovich543afa92017-04-21 14:48:03 +0300141 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300142 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;
Tatyana Leontovich644446f2017-06-08 13:43:36 +0300145 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 +0300146 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300147 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300148 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
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300166- 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'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300175 cmd: |
176 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
177 cat << "EOF" >> /etc/salt/minion.d/minion.conf
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300178 id: {{ ssh['node_name'] }}
179 master: {{ config.salt.salt_master_host }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300180 EOF
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300181 eatmydata apt-get install -y salt-minion;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300182 echo "Check for system info and metadata availability ...";
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300183 salt-call --no-color grains.items;
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300184 salt-call --no-color pillar.items;
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300185 node_name: {{ ssh['node_name'] }}
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300186 retry: {count: 1, delay: 1}
187 skip_fail: false
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300188{% endfor %}
189
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300190
Dennis Dmitriev8f0f80f2017-04-27 01:04:39 +0300191- 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
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300197- description: Configure salt adoptors on cfg01
198 cmd: |
199 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
200 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
201 node_name: {{ HOSTNAME_CFG01 }}
202 retry: {count: 1, delay: 1}
203 skip_fail: false
204
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300205# Prepare salt services and nodes settings
206- description: Run 'linux' formula on cfg01
Tatyana Leontovich18013122017-06-09 20:24:50 +0300207 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300208 node_name: {{ HOSTNAME_CFG01 }}
209 retry: {count: 1, delay: 5}
210 skip_fail: false
211
212- description: Run 'openssh' formula on cfg01
213 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
214 -C 'I@salt:master' state.sls openssh;
215 salt --hard-crash --state-output=mixed --state-verbose=False
216 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Tatyana Leontovich18013122017-06-09 20:24:50 +0300217 yes/' /etc/ssh/sshd_config && service ssh reload";
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300218 node_name: {{ HOSTNAME_CFG01 }}
219 retry: {count: 3, delay: 5}
220 skip_fail: false
221
222- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
223 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
224 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
225 node_name: {{ HOSTNAME_CFG01 }}
226 retry: {count: 1, delay: 1}
227 skip_fail: false
228
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300229- description: Run 'salt.master' formula on cfg01
Tatyana Leontovich18013122017-06-09 20:24:50 +0300230 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 +0300231 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300232 retry: {count: 2, delay: 5}
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300233 skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300234
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300235- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
236 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
237 -C 'I@salt:master' state.sls reclass
238 node_name: {{ HOSTNAME_CFG01 }}
239 retry: {count: 1, delay: 5}
240 skip_fail: false
241
242- description: Refresh pillars on all minions
243 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
244 node_name: {{ HOSTNAME_CFG01 }}
245 retry: {count: 1, delay: 5}
246 skip_fail: false
247
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300248- description: Show reclass-salt --top
Dennis Dmitriev4db5bf22017-05-13 19:31:17 +0300249 cmd: reclass-salt --top
250 node_name: {{ HOSTNAME_CFG01 }}
251 retry: {count: 1, delay: 5}
252 skip_fail: false
253
Tatyana Leontovich18013122017-06-09 20:24:50 +0300254- description: Sync all salt resources
255 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300256 node_name: {{ HOSTNAME_CFG01 }}
257 retry: {count: 1, delay: 5}
258 skip_fail: false
259
Tatyana Leontovich18013122017-06-09 20:24:50 +0300260- description: Configure linux on master
261 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
262 node_name: {{ HOSTNAME_CFG01 }}
263 retry: {count: 1, delay: 5}
264 skip_fail: false
265
266- description: Configure minion on master
267 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
268 -C 'I@salt:master' state.sls 'salt.minion'
269 node_name: {{ HOSTNAME_CFG01 }}
270 retry: {count: 3, delay: 10}
271 skip_fail: false
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300272
273# Bootstrap all nodes
274
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300275- description: Configure linux on other nodes
Tatyana Leontovich18013122017-06-09 20:24:50 +0300276 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls 'linux'
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300277 node_name: {{ HOSTNAME_CFG01 }}
278 retry: {count: 1, delay: 5}
279 skip_fail: false
280
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300281- description: Configure openssh on all nodes
Tatyana Leontovich18013122017-06-09 20:24:50 +0300282 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls openssh;
283 salt --hard-crash --state-output=mixed --state-verbose=False
284 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
285 yes/' /etc/ssh/sshd_config && service ssh reload"
Tatyana Leontovichd8bf14f2017-04-19 12:20:50 +0300286 node_name: {{ HOSTNAME_CFG01 }}
287 retry: {count: 1, delay: 5}
288 skip_fail: false
289
Dennis Dmitrieva9e6da82017-04-26 23:23:22 +0300290- description: Configure salt.minion on other nodes
Tatyana Leontovich18013122017-06-09 20:24:50 +0300291 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 +0300292 node_name: {{ HOSTNAME_CFG01 }}
293 retry: {count: 3, delay: 5}
294 skip_fail: false
295
296- description: Check salt minion versions on slaves
297 cmd: salt '*' test.version
298 node_name: {{ HOSTNAME_CFG01 }}
299 retry: {count: 1, delay: 5}
300 skip_fail: false
301
302- description: Check salt top states on nodes
303 cmd: salt '*' state.show_top
304 node_name: {{ HOSTNAME_CFG01 }}
305 retry: {count: 1, delay: 5}
306 skip_fail: false
307
308- description: Configure ntp and rsyslog on nodes
Tatyana Leontovich18013122017-06-09 20:24:50 +0300309 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 +0300310 node_name: {{ HOSTNAME_CFG01 }}
311 retry: {count: 1, delay: 10}
312 skip_fail: false
313
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +0300314- description: Hack gtw node
315 cmd: salt 'gtw*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4";
316 node_name: {{ HOSTNAME_CFG01 }}
317 retry: {count: 1, delay: 10}
318 skip_fail: false
319
320- description: Hack cmp01 node
321 cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
322 node_name: {{ HOSTNAME_CFG01 }}
323 retry: {count: 1, delay: 10}
324 skip_fail: false
325
326- description: Hack cmp02 node
327 cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
328 node_name: {{ HOSTNAME_CFG01 }}
329 retry: {count: 1, delay: 10}
330 skip_fail: false