blob: 4bacd55e2f89edfef0137cc174881f94d5e33a6b [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') %}
Valentyn Yakovlev08acf9f2017-06-07 14:02:36 +03005{% set SALT_MODELS_BRANCH = os_env('SALT_MODELS_BRANCH','master') %}
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +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', '172.16.10.0/24')) %}
15{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '192.168.10.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]) %}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020019
20# Install salt to the config node
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020021- description: Installing salt master on cfg01
22 cmd: apt-get install -y reclass git; apt-get install -y salt-master
23 node_name: {{ HOSTNAME_CFG01 }}
24 retry: {count: 1, delay: 1}
25 skip_fail: false
26
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020027- description: Configure salt-master on cfg01
28 cmd: |
29 cat << 'EOF' >> /etc/salt/master.d/master.conf
30 file_roots:
31 base:
32 - /usr/share/salt-formulas/env
33 pillar_opts: False
34 open_mode: True
35 reclass: &reclass
36 storage_type: yaml_fs
37 inventory_base_uri: /srv/salt/reclass
38 ext_pillar:
39 - reclass: *reclass
40 master_tops:
41 reclass: *reclass
42 EOF
43 node_name: {{ HOSTNAME_CFG01 }}
44 retry: {count: 1, delay: 1}
45 skip_fail: false
46
47- description: Configure GIT settings and certificates
48 cmd: touch /root/.git_trusted_certs.pem;
Matthew Mosesohnd0632b82017-05-30 17:51:30 +030049 for server in github.com; do
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020050 openssl s_client -showcerts -connect $server:443 </dev/null
51 | openssl x509 -outform PEM
52 >> /root/.git_trusted_certs.pem;
53 done;
54 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
55 HOME=/root git config --global user.email "tcp-qa@example.com";
56 HOME=/root git config --global user.name "TCP QA";
57 node_name: {{ HOSTNAME_CFG01 }}
58 retry: {count: 1, delay: 1}
59 skip_fail: false
60
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020061- description: Clone reclass models with submodules
Tatyana Leontovichcf37cb22017-05-19 14:59:38 +030062 cmd: |
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020063 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Valentyn Yakovlev08acf9f2017-06-07 14:02:36 +030064 git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
65 pushd /srv/salt/reclass && git checkout {{ SALT_MODELS_COMMIT }} && popd;
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020066 mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030067
68 # Replace firstly to an intermediate value to avoid intersection between
69 # already replaced and replacing networks.
70 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
71 # 192.168.10 -> 10.16.0 (generated network for admin)
72 # 10.16.0 -> <external network>
73 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Tatyana Leontovich573584a2017-05-19 14:54:00 +030074 find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
75 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 +030076
77 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
78 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
79
80 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
81
82 # Disable checkouting the model from remote repository
83 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
84 # local storage
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +020085 reclass:
86 storage:
87 data_source:
88 engine: local
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030089 EOF
Tatyana Leontovichcf37cb22017-05-19 14:59:38 +030090
91 # Show the changes to the console
92 cd /srv/salt/reclass/; git diff
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020093 node_name: {{ HOSTNAME_CFG01 }}
94 retry: {count: 1, delay: 1}
95 skip_fail: false
96
Tatyana Leontovichcf37cb22017-05-19 14:59:38 +030097
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020098- description: Configure reclass
99 cmd: |
100 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Tatyana Leontovich5fbd0382017-05-19 19:41:24 +0300101 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200102 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
103 which wget > /dev/null || (apt-get update; apt-get install -y wget);
104 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
105 wget -O - "${FORMULA_GPG}" | apt-key add -;
106 apt-get clean; apt-get update;
107 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich644446f2017-06-08 13:43:36 +0300108 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch");
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200109 echo -e "\nInstalling all required salt formulas\n";
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300110 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200111 for formula_service in "${formula_services[@]}"; do
112 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
113 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
114 done;
115 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
116 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
117 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
118
119 cat << 'EOF' >> /etc/reclass/reclass-config.yml
120 storage_type: yaml_fs
121 pretty_print: True
122 output: yaml
123 inventory_base_uri: /srv/salt/reclass
124 EOF
125 node_name: {{ HOSTNAME_CFG01 }}
126 retry: {count: 1, delay: 1}
127 skip_fail: false
128
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300129- description: Restart salt-master service
130 cmd: |
131 systemctl restart salt-master;
132 node_name: {{ HOSTNAME_CFG01 }}
133 retry: {count: 1, delay: 5}
134 skip_fail: false
135
136{% for ssh in config.underlay.ssh %}
137- description: Configure salt-minion on {{ ssh['node_name'] }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200138 cmd: |
139 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
140 cat << "EOF" >> /etc/salt/minion.d/minion.conf
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300141 id: {{ ssh['node_name'] }}
142 master: {{ config.salt.salt_master_host }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200143 EOF
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300144 eatmydata apt-get install -y salt-minion;
145 echo "Check for system info and metadata availability ...";
146 salt-call --no-color grains.items;
147 salt-call --no-color pillar.items;
148 node_name: {{ ssh['node_name'] }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200149 retry: {count: 1, delay: 1}
150 skip_fail: false
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300151{% endfor %}
152
153- description: Accept salt keys from all the nodes
154 cmd: salt-key -A -y
155 node_name: {{ HOSTNAME_CFG01 }}
156 retry: {count: 1, delay: 5}
157 skip_fail: true
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200158
159- description: Configure salt adoptors on cfg01
160 cmd: |
161 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
162 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
163 node_name: {{ HOSTNAME_CFG01 }}
164 retry: {count: 1, delay: 1}
165 skip_fail: false
166
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200167# Prepare salt services and nodes settings
168- description: Run 'linux' formula on cfg01
169 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
170 -C 'I@salt:master' state.sls linux;
171 node_name: {{ HOSTNAME_CFG01 }}
172 retry: {count: 1, delay: 5}
173 skip_fail: false
174
175- description: Run 'openssh' formula on cfg01
176 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
177 -C 'I@salt:master' state.sls openssh;
178 salt --hard-crash --state-output=mixed --state-verbose=False
179 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
180 yes/' /etc/ssh/sshd_config && service ssh restart";
181 node_name: {{ HOSTNAME_CFG01 }}
182 retry: {count: 3, delay: 5}
183 skip_fail: false
184
185- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
186 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
187 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
188 node_name: {{ HOSTNAME_CFG01 }}
189 retry: {count: 1, delay: 1}
190 skip_fail: false
191
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300192- description: Run 'salt.master' formula on cfg01
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200193 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
194 -C 'I@salt:master' state.sls salt.master.service;
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200195 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300196 retry: {count: 2, delay: 5}
197 skip_fail: false
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200198
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300199- description: Run 'salt' formula on cfg01 with workaround proposed in PROD-10894
200 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
201 -C 'I@salt:master' state.sls salt;
202 salt --hard-crash --state-output=mixed --state-verbose=False
203 -C 'I@salt:master' saltutil.sync_all
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200204 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300205 retry: {count: 5, delay: 5}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200206 skip_fail: false
207
208- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
209 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
210 -C 'I@salt:master' state.sls reclass
211 node_name: {{ HOSTNAME_CFG01 }}
212 retry: {count: 1, delay: 5}
213 skip_fail: false
214
215- description: Refresh pillars on all minions
216 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
217 node_name: {{ HOSTNAME_CFG01 }}
218 retry: {count: 1, delay: 5}
219 skip_fail: false
220
221- description: Sync all salt resources
222 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
223 node_name: {{ HOSTNAME_CFG01 }}
224 retry: {count: 1, delay: 5}
225 skip_fail: false
226
Sergii Golovatiuk5b659d42017-05-26 17:38:06 +0200227- description: Show reclass-salt --top
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300228 cmd: reclass-salt --top
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200229 node_name: {{ HOSTNAME_CFG01 }}
230 retry: {count: 1, delay: 5}
231 skip_fail: false
232
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300233- description: Execute salt.minion.cert
234 cmd: salt-call --no-color state.sls salt.minion.cert -l info;
235 node_name: {{ HOSTNAME_CFG01 }}
236 retry: {count: 1, delay: 5}
237 skip_fail: false
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200238
239# Bootstrap all nodes
240
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300241- description: Configure linux on other nodes
242 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +0300243 cfg01* and not mon*' state.sls linux
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200244 node_name: {{ HOSTNAME_CFG01 }}
245 retry: {count: 1, delay: 5}
246 skip_fail: false
247
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +0300248- description: Configure linux on mon nodes
249 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'mon*' state.sls linux
250 node_name: {{ HOSTNAME_CFG01 }}
251 retry: {count: 2, delay: 5}
252 skip_fail: false
253
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200254- description: Configure openssh on all nodes
255 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300256 cfg01*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200257 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
258 yes/' /etc/ssh/sshd_config && service ssh restart"
259 node_name: {{ HOSTNAME_CFG01 }}
260 retry: {count: 1, delay: 5}
261 skip_fail: false
262
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300263- description: Configure salt.minion on other nodes
264 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
265 cfg01*' state.sls salt.minion
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200266 node_name: {{ HOSTNAME_CFG01 }}
267 retry: {count: 3, delay: 5}
268 skip_fail: false
269
270- description: Check salt minion versions on slaves
271 cmd: salt '*' test.version
272 node_name: {{ HOSTNAME_CFG01 }}
273 retry: {count: 1, delay: 5}
274 skip_fail: false
275
276- description: Check salt top states on nodes
277 cmd: salt '*' state.show_top
278 node_name: {{ HOSTNAME_CFG01 }}
279 retry: {count: 1, delay: 5}
280 skip_fail: false
281
282- description: Configure ntp and rsyslog on nodes
283 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog
284 node_name: {{ HOSTNAME_CFG01 }}
285 retry: {count: 1, delay: 10}
286 skip_fail: false