blob: 884485194a767bb96cd3ed509cfb91def9cc6742 [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 Leontovichcf37cb22017-05-19 14:59:38 +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
Tatyana Leontovichcf37cb22017-05-19 14:59:38 +030089
90 # Show the changes to the console
91 cd /srv/salt/reclass/; git diff
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020092 node_name: {{ HOSTNAME_CFG01 }}
93 retry: {count: 1, delay: 1}
94 skip_fail: false
95
Tatyana Leontovichcf37cb22017-05-19 14:59:38 +030096
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +020097- description: Configure reclass
98 cmd: |
99 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Tatyana Leontovich5fbd0382017-05-19 19:41:24 +0300100 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200101 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
102 which wget > /dev/null || (apt-get update; apt-get install -y wget);
103 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
104 wget -O - "${FORMULA_GPG}" | apt-key add -;
105 apt-get clean; apt-get update;
106 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich9ce755b2017-05-19 16:24:32 +0300107 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf");
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200108 echo -e "\nInstalling all required salt formulas\n";
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300109 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200110 for formula_service in "${formula_services[@]}"; do
111 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
112 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
113 done;
114 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
115 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
116 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
117
118 cat << 'EOF' >> /etc/reclass/reclass-config.yml
119 storage_type: yaml_fs
120 pretty_print: True
121 output: yaml
122 inventory_base_uri: /srv/salt/reclass
123 EOF
124 node_name: {{ HOSTNAME_CFG01 }}
125 retry: {count: 1, delay: 1}
126 skip_fail: false
127
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300128- description: Restart salt-master service
129 cmd: |
130 systemctl restart salt-master;
131 node_name: {{ HOSTNAME_CFG01 }}
132 retry: {count: 1, delay: 5}
133 skip_fail: false
134
135{% for ssh in config.underlay.ssh %}
136- description: Configure salt-minion on {{ ssh['node_name'] }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200137 cmd: |
138 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
139 cat << "EOF" >> /etc/salt/minion.d/minion.conf
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300140 id: {{ ssh['node_name'] }}
141 master: {{ config.salt.salt_master_host }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200142 EOF
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300143 eatmydata apt-get install -y salt-minion;
144 echo "Check for system info and metadata availability ...";
145 salt-call --no-color grains.items;
146 salt-call --no-color pillar.items;
147 node_name: {{ ssh['node_name'] }}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200148 retry: {count: 1, delay: 1}
149 skip_fail: false
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300150{% endfor %}
151
152- description: Accept salt keys from all the nodes
153 cmd: salt-key -A -y
154 node_name: {{ HOSTNAME_CFG01 }}
155 retry: {count: 1, delay: 5}
156 skip_fail: true
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200157
158- description: Configure salt adoptors on cfg01
159 cmd: |
160 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
161 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
162 node_name: {{ HOSTNAME_CFG01 }}
163 retry: {count: 1, delay: 1}
164 skip_fail: false
165
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200166# Prepare salt services and nodes settings
167- description: Run 'linux' formula on cfg01
168 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
169 -C 'I@salt:master' state.sls linux;
170 node_name: {{ HOSTNAME_CFG01 }}
171 retry: {count: 1, delay: 5}
172 skip_fail: false
173
174- description: Run 'openssh' formula on cfg01
175 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
176 -C 'I@salt:master' state.sls openssh;
177 salt --hard-crash --state-output=mixed --state-verbose=False
178 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
179 yes/' /etc/ssh/sshd_config && service ssh restart";
180 node_name: {{ HOSTNAME_CFG01 }}
181 retry: {count: 3, delay: 5}
182 skip_fail: false
183
184- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
185 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
186 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
187 node_name: {{ HOSTNAME_CFG01 }}
188 retry: {count: 1, delay: 1}
189 skip_fail: false
190
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300191- description: Run 'salt.master' formula on cfg01
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200192 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
193 -C 'I@salt:master' state.sls salt.master.service;
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200194 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300195 retry: {count: 2, delay: 5}
196 skip_fail: false
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200197
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300198- description: Run 'salt' formula on cfg01 with workaround proposed in PROD-10894
199 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
200 -C 'I@salt:master' state.sls salt;
201 salt --hard-crash --state-output=mixed --state-verbose=False
202 -C 'I@salt:master' saltutil.sync_all
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200203 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300204 retry: {count: 5, delay: 5}
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200205 skip_fail: false
206
207- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
208 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
209 -C 'I@salt:master' state.sls reclass
210 node_name: {{ HOSTNAME_CFG01 }}
211 retry: {count: 1, delay: 5}
212 skip_fail: false
213
214- description: Refresh pillars on all minions
215 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
216 node_name: {{ HOSTNAME_CFG01 }}
217 retry: {count: 1, delay: 5}
218 skip_fail: false
219
220- description: Sync all salt resources
221 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
222 node_name: {{ HOSTNAME_CFG01 }}
223 retry: {count: 1, delay: 5}
224 skip_fail: false
225
226- description: Show reclass-salt --top
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300227 cmd: reclass-salt --top
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200228 node_name: {{ HOSTNAME_CFG01 }}
229 retry: {count: 1, delay: 5}
230 skip_fail: false
231
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300232- description: Execute salt.minion.cert
233 cmd: salt-call --no-color state.sls salt.minion.cert -l info;
234 node_name: {{ HOSTNAME_CFG01 }}
235 retry: {count: 1, delay: 5}
236 skip_fail: false
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200237
238# Bootstrap all nodes
239
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300240- description: Configure linux on other nodes
241 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +0300242 cfg01* and not mon*' state.sls linux
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200243 node_name: {{ HOSTNAME_CFG01 }}
244 retry: {count: 1, delay: 5}
245 skip_fail: false
246
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +0300247- description: Configure linux on mon nodes
248 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'mon*' state.sls linux
249 node_name: {{ HOSTNAME_CFG01 }}
250 retry: {count: 2, delay: 5}
251 skip_fail: false
252
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200253- description: Configure openssh on all nodes
254 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300255 cfg01*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200256 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
257 yes/' /etc/ssh/sshd_config && service ssh restart"
258 node_name: {{ HOSTNAME_CFG01 }}
259 retry: {count: 1, delay: 5}
260 skip_fail: false
261
Tatyana Leontovich573584a2017-05-19 14:54:00 +0300262- description: Configure salt.minion on other nodes
263 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
264 cfg01*' state.sls salt.minion
Sergii Golovatiuk57bb8e72017-05-16 19:49:49 +0200265 node_name: {{ HOSTNAME_CFG01 }}
266 retry: {count: 3, delay: 5}
267 skip_fail: false
268
269- description: Check salt minion versions on slaves
270 cmd: salt '*' test.version
271 node_name: {{ HOSTNAME_CFG01 }}
272 retry: {count: 1, delay: 5}
273 skip_fail: false
274
275- description: Check salt top states on nodes
276 cmd: salt '*' state.show_top
277 node_name: {{ HOSTNAME_CFG01 }}
278 retry: {count: 1, delay: 5}
279 skip_fail: false
280
281- description: Configure ntp and rsyslog on nodes
282 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog
283 node_name: {{ HOSTNAME_CFG01 }}
284 retry: {count: 1, delay: 10}
285 skip_fail: false