blob: 535d3786a4af31d9a1f5b989886f40239d555f2d [file] [log] [blame]
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +03001{% from 'virtual-mcp11-k8s-contrail/underlay.yaml' import HOSTNAME_CFG01 with context %}
2{% from 'virtual-mcp11-k8s-contrail/underlay.yaml' import REPOSITORY_SUITE with context %}
Tatyana Leontovich3162aa22017-05-25 19:03:43 +03003{% from 'virtual-mcp11-k8s-contrail/underlay.yaml' import DOMAIN_NAME with context %}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +03004
5{% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab') %}
6{% 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
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]) %}
19
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +030020# Install salt to the config node
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030021- description: Installing salt master on cfg01
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +030022 cmd: apt-get install -y reclass git; apt-get install -y salt-master
Sergii Golovatiukc504a392017-05-22 21:41:06 +020023 node_name: {{ HOSTNAME_CFG01 }}
24 retry: {count: 1, delay: 1}
25 skip_fail: false
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030026
27- 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;
49 for server in git.tcpcloud.eu github.com; do
50 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
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030061- description: Clone reclass models with submodules
62 cmd: |
63 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
64 git clone -b {{ SALT_MODELS_COMMIT }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +030065
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030066 mkdir -p /srv/salt/reclass/classes/service;
67
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.
74 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 Leontovich508d0cb2017-05-26 15:46:24 +030076
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030077 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' {} +
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030079
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +030080 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030081 # Disable checkouting the model from remote repository
82 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
Tatyana Leontovich3162aa22017-05-25 19:03:43 +030083 parameters:
84 _param:
85 linux_system_codename: xenial
86 reclass_data_revision: master
87 linux:
88 system:
89 name: {{ HOSTNAME_CFG01 }}
90 domain: {{ DOMAIN_NAME }}.local
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030091 # local storage
92 reclass:
93 storage:
94 data_source:
95 engine: local
96 EOF
97
98 # Show the changes to the console
99 cd /srv/salt/reclass/; git diff
100 node_name: {{ HOSTNAME_CFG01 }}
101 retry: {count: 1, delay: 1}
102 skip_fail: false
103
104- description: Configure reclass
105 cmd: |
106 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Tatyana Leontovicheed70d72017-05-25 16:32:17 +0300107 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300108 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
109 which wget > /dev/null || (apt-get update; apt-get install -y wget);
110 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
111 wget -O - "${FORMULA_GPG}" | apt-key add -;
112 apt-get clean; apt-get update;
113 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovicheed70d72017-05-25 16:32:17 +0300114 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf");
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300115 echo -e "\nInstalling all required salt formulas\n";
116 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
117 for formula_service in "${formula_services[@]}"; do
118 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
119 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
120 done;
121 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
122 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
123 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
124
125 cat << 'EOF' >> /etc/reclass/reclass-config.yml
126 storage_type: yaml_fs
127 pretty_print: True
128 output: yaml
129 inventory_base_uri: /srv/salt/reclass
130 EOF
131 node_name: {{ HOSTNAME_CFG01 }}
132 retry: {count: 1, delay: 1}
133 skip_fail: false
134
135- description: Restart salt-master service
136 cmd: |
137 systemctl restart salt-master;
138 node_name: {{ HOSTNAME_CFG01 }}
139 retry: {count: 1, delay: 5}
140 skip_fail: false
141
142{% for ssh in config.underlay.ssh %}
143- description: Configure salt-minion on {{ ssh['node_name'] }}
144 cmd: |
145 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
146 cat << "EOF" >> /etc/salt/minion.d/minion.conf
147 id: {{ ssh['node_name'] }}
148 master: {{ config.salt.salt_master_host }}
149 EOF
150 eatmydata apt-get install -y salt-minion;
151 echo "Check for system info and metadata availability ...";
152 salt-call --no-color grains.items;
153 salt-call --no-color pillar.items;
154 node_name: {{ ssh['node_name'] }}
155 retry: {count: 1, delay: 1}
156 skip_fail: false
157{% endfor %}
158
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300159- description: Accept salt keys from all the nodes
160 cmd: salt-key -A -y
161 node_name: {{ HOSTNAME_CFG01 }}
162 retry: {count: 1, delay: 5}
163 skip_fail: true
164
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300165- description: Configure salt adoptors on cfg01
166 cmd: |
167 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
168 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
169 node_name: {{ HOSTNAME_CFG01 }}
170 retry: {count: 1, delay: 1}
171 skip_fail: false
172
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300173# Prepare salt services and nodes settings
174- description: Run 'linux' formula on cfg01
175 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
176 -C 'I@salt:master' state.sls linux;
177 node_name: {{ HOSTNAME_CFG01 }}
178 retry: {count: 1, delay: 5}
179 skip_fail: false
180
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300181- description: Run 'openssh' formula on cfg01
182 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
183 -C 'I@salt:master' state.sls openssh;
184 salt --hard-crash --state-output=mixed --state-verbose=False
185 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
186 yes/' /etc/ssh/sshd_config && service ssh restart";
187 node_name: {{ HOSTNAME_CFG01 }}
188 retry: {count: 3, delay: 5}
189 skip_fail: false
190
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300191- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
192 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
193 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
194 node_name: {{ HOSTNAME_CFG01 }}
195 retry: {count: 1, delay: 1}
196 skip_fail: false
197
198- description: Run 'salt.master' formula on cfg01
199 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
200 -C 'I@salt:master' state.sls salt.master.service;
201 node_name: {{ HOSTNAME_CFG01 }}
202 retry: {count: 2, delay: 5}
203 skip_fail: false
204
205- description: Run 'salt' formula on cfg01 with workaround proposed in PROD-10894
206 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
207 -C 'I@salt:master' state.sls salt;
208 salt --hard-crash --state-output=mixed --state-verbose=False
209 -C 'I@salt:master' saltutil.sync_all
210 node_name: {{ HOSTNAME_CFG01 }}
211 retry: {count: 5, delay: 5}
212 skip_fail: false
213
214- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
215 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
216 -C 'I@salt:master' state.sls reclass
217 node_name: {{ HOSTNAME_CFG01 }}
218 retry: {count: 1, delay: 5}
219 skip_fail: false
220
221- description: Refresh pillars on all minions
222 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
223 node_name: {{ HOSTNAME_CFG01 }}
224 retry: {count: 1, delay: 5}
225 skip_fail: false
226
227- description: Sync all salt resources
228 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
229 node_name: {{ HOSTNAME_CFG01 }}
230 retry: {count: 1, delay: 5}
231 skip_fail: false
232
233- description: Show reclass-salt --top
234 cmd: reclass-salt --top
235 node_name: {{ HOSTNAME_CFG01 }}
236 retry: {count: 1, delay: 5}
237 skip_fail: false
238
239- description: Execute salt.minion.cert
240 cmd: salt-call --no-color state.sls salt.minion.cert -l info;
241 node_name: {{ HOSTNAME_CFG01 }}
242 retry: {count: 1, delay: 5}
243 skip_fail: false
244
245# Bootstrap all nodes
246
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +0300247- description: Configure linux on other nodes
248 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
249 cfg01*' state.sls linux
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300250 node_name: {{ HOSTNAME_CFG01 }}
251 retry: {count: 1, delay: 5}
252 skip_fail: false
253
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300254- description: Configure openssh on all nodes
255 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +0300256 cfg01*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300257 -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 Leontovich508d0cb2017-05-26 15:46:24 +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
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300266 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