blob: 2172912e49131f323be6db1bd87b910157967032 [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;
48 for server in git.tcpcloud.eu github.com; do
49 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 Leontovich573584a2017-05-19 14:54:00 +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;
64
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020065 mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030066
67 # Replace firstly to an intermediate value to avoid intersection between
68 # already replaced and replacing networks.
69 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
70 # 192.168.10 -> 10.16.0 (generated network for admin)
71 # 10.16.0 -> <external network>
72 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Tatyana Leontovich573584a2017-05-19 14:54:00 +030073 find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
74 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 +030075
76 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
77 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
78
79 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/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
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020089 node_name: {{ HOSTNAME_CFG01 }}
90 retry: {count: 1, delay: 1}
91 skip_fail: false
92
93- description: Configure reclass
94 cmd: |
95 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Tatyana Leontovich573584a2017-05-19 14:54:00 +030096 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial stable salt};
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020097 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
98 which wget > /dev/null || (apt-get update; apt-get install -y wget);
99 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
100 wget -O - "${FORMULA_GPG}" | apt-key add -;
101 apt-get clean; apt-get update;
102 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300103 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon");
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200104 echo -e "\nInstalling all required salt formulas\n";
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300105 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200106 for formula_service in "${formula_services[@]}"; do
107 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
108 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
109 done;
110 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
111 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
112 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
113
114 cat << 'EOF' >> /etc/reclass/reclass-config.yml
115 storage_type: yaml_fs
116 pretty_print: True
117 output: yaml
118 inventory_base_uri: /srv/salt/reclass
119 EOF
120 node_name: {{ HOSTNAME_CFG01 }}
121 retry: {count: 1, delay: 1}
122 skip_fail: false
123
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300124- description: Restart salt-master service
125 cmd: |
126 systemctl restart salt-master;
127 node_name: {{ HOSTNAME_CFG01 }}
128 retry: {count: 1, delay: 5}
129 skip_fail: false
130
131{% for ssh in config.underlay.ssh %}
132- description: Configure salt-minion on {{ ssh['node_name'] }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200133 cmd: |
134 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
135 cat << "EOF" >> /etc/salt/minion.d/minion.conf
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300136 id: {{ ssh['node_name'] }}
137 master: {{ config.salt.salt_master_host }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200138 EOF
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300139 eatmydata apt-get install -y salt-minion;
140 echo "Check for system info and metadata availability ...";
141 salt-call --no-color grains.items;
142 salt-call --no-color pillar.items;
143 node_name: {{ ssh['node_name'] }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200144 retry: {count: 1, delay: 1}
145 skip_fail: false
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300146{% endfor %}
147
148- description: Accept salt keys from all the nodes
149 cmd: salt-key -A -y
150 node_name: {{ HOSTNAME_CFG01 }}
151 retry: {count: 1, delay: 5}
152 skip_fail: true
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200153
154- description: Configure salt adoptors on cfg01
155 cmd: |
156 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
157 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
158 node_name: {{ HOSTNAME_CFG01 }}
159 retry: {count: 1, delay: 1}
160 skip_fail: false
161
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200162# Prepare salt services and nodes settings
163- description: Run 'linux' formula on cfg01
164 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
165 -C 'I@salt:master' state.sls linux;
166 node_name: {{ HOSTNAME_CFG01 }}
167 retry: {count: 1, delay: 5}
168 skip_fail: false
169
170- description: Run 'openssh' formula on cfg01
171 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
172 -C 'I@salt:master' state.sls openssh;
173 salt --hard-crash --state-output=mixed --state-verbose=False
174 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
175 yes/' /etc/ssh/sshd_config && service ssh restart";
176 node_name: {{ HOSTNAME_CFG01 }}
177 retry: {count: 3, delay: 5}
178 skip_fail: false
179
180- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
181 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
182 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
183 node_name: {{ HOSTNAME_CFG01 }}
184 retry: {count: 1, delay: 1}
185 skip_fail: false
186
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300187- description: Run 'salt.master' formula on cfg01
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200188 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
189 -C 'I@salt:master' state.sls salt.master.service;
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200190 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300191 retry: {count: 2, delay: 5}
192 skip_fail: false
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200193
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300194- description: Run 'salt' formula on cfg01 with workaround proposed in PROD-10894
195 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
196 -C 'I@salt:master' state.sls salt;
197 salt --hard-crash --state-output=mixed --state-verbose=False
198 -C 'I@salt:master' saltutil.sync_all
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200199 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300200 retry: {count: 5, delay: 5}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200201 skip_fail: false
202
203- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
204 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
205 -C 'I@salt:master' state.sls reclass
206 node_name: {{ HOSTNAME_CFG01 }}
207 retry: {count: 1, delay: 5}
208 skip_fail: false
209
210- description: Refresh pillars on all minions
211 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
212 node_name: {{ HOSTNAME_CFG01 }}
213 retry: {count: 1, delay: 5}
214 skip_fail: false
215
216- description: Sync all salt resources
217 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
218 node_name: {{ HOSTNAME_CFG01 }}
219 retry: {count: 1, delay: 5}
220 skip_fail: false
221
222- description: Show reclass-salt --top
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300223 cmd: reclass-salt --top
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200224 node_name: {{ HOSTNAME_CFG01 }}
225 retry: {count: 1, delay: 5}
226 skip_fail: false
227
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300228- description: Execute salt.minion.cert
229 cmd: salt-call --no-color state.sls salt.minion.cert -l info;
230 node_name: {{ HOSTNAME_CFG01 }}
231 retry: {count: 1, delay: 5}
232 skip_fail: false
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200233
234# Bootstrap all nodes
235
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300236- description: Configure linux on other nodes
237 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
238 cfg01*' state.sls linux
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200239 node_name: {{ HOSTNAME_CFG01 }}
240 retry: {count: 1, delay: 5}
241 skip_fail: false
242
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200243- description: Configure openssh on all nodes
244 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300245 cfg01*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200246 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
247 yes/' /etc/ssh/sshd_config && service ssh restart"
248 node_name: {{ HOSTNAME_CFG01 }}
249 retry: {count: 1, delay: 5}
250 skip_fail: false
251
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300252- description: Configure salt.minion on other nodes
253 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
254 cfg01*' state.sls salt.minion
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200255 node_name: {{ HOSTNAME_CFG01 }}
256 retry: {count: 3, delay: 5}
257 skip_fail: false
258
259- description: Check salt minion versions on slaves
260 cmd: salt '*' test.version
261 node_name: {{ HOSTNAME_CFG01 }}
262 retry: {count: 1, delay: 5}
263 skip_fail: false
264
265- description: Check salt top states on nodes
266 cmd: salt '*' state.show_top
267 node_name: {{ HOSTNAME_CFG01 }}
268 retry: {count: 1, delay: 5}
269 skip_fail: false
270
271- description: Configure ntp and rsyslog on nodes
272 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog
273 node_name: {{ HOSTNAME_CFG01 }}
274 retry: {count: 1, delay: 10}
275 skip_fail: false