blob: 72ad38d677a9a4b3389bebc7f314bf38fa8017e7 [file] [log] [blame]
Artem Panchenkoedf70ef2017-06-13 09:14:34 +03001{% from 'virtual-mcp11-k8s-calico-minimal/underlay.yaml' import HOSTNAME_CFG01 with context %}
2{% from 'virtual-mcp11-k8s-calico-minimal/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_BRANCH = os_env('SALT_MODELS_BRANCH','master') %}
6{% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %}
7
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +03008# Reference to a patch that should be applied to the model if required, for example: export SALT_MODELS_REF_CHANGE=refs/changes/19/7219/12
9{% set SALT_MODELS_REF_CHANGE = os_env('SALT_MODELS_REF_CHANGE', '') %}
10
Artem Panchenkoedf70ef2017-06-13 09:14:34 +030011# Address pools for reclass cluster model are taken in the following order:
12# 1. environment variables,
13# 2. config.underlay.address_pools based on fuel-devops address pools
14# (see generated '.ini' file after underlay is created),
15# 3. defaults
16{% set address_pools = config.underlay.address_pools %}
17{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '172.16.10.0/24')) %}
18{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '192.168.10.0/24')) %}
19
20{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
21{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
22
23# Install salt to the config node
24- description: Installing salt master on cfg01
25 cmd: apt-get install -y reclass git; apt-get install -y salt-master
26 node_name: {{ HOSTNAME_CFG01 }}
27 retry: {count: 1, delay: 1}
28 skip_fail: false
29
30- description: Configure salt-master on cfg01
31 cmd: |
32 cat << 'EOF' >> /etc/salt/master.d/master.conf
33 file_roots:
34 base:
35 - /usr/share/salt-formulas/env
36 pillar_opts: False
37 open_mode: True
38 reclass: &reclass
39 storage_type: yaml_fs
40 inventory_base_uri: /srv/salt/reclass
41 ext_pillar:
42 - reclass: *reclass
43 master_tops:
44 reclass: *reclass
45 EOF
46 node_name: {{ HOSTNAME_CFG01 }}
47 retry: {count: 1, delay: 1}
48 skip_fail: false
49
50- description: Configure GIT settings and certificates
51 cmd: touch /root/.git_trusted_certs.pem;
52 for server in github.com; do
53 openssl s_client -showcerts -connect $server:443 </dev/null
54 | openssl x509 -outform PEM
55 >> /root/.git_trusted_certs.pem;
56 done;
57 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
58 HOME=/root git config --global user.email "tcp-qa@example.com";
59 HOME=/root git config --global user.name "TCP QA";
60 node_name: {{ HOSTNAME_CFG01 }}
61 retry: {count: 1, delay: 1}
62 skip_fail: false
63
64- description: Clone reclass models with submodules
65 cmd: |
66 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
67 git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
68 pushd /srv/salt/reclass && git checkout {{ SALT_MODELS_COMMIT }} && popd
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030069 {%- if SALT_MODELS_REF_CHANGE != '' %}
70 pushd /srv/salt/reclass && git fetch {{ SALT_MODELS_REPOSITORY }} {{ SALT_MODELS_REF_CHANGE }} && git checkout FETCH_HEAD && popd;
71 {%- endif %}
Artem Panchenkoedf70ef2017-06-13 09:14:34 +030072 mkdir -p /srv/salt/reclass/classes/service;
73
74 # Replace firstly to an intermediate value to avoid intersection between
75 # already replaced and replacing networks.
76 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
77 # 192.168.10 -> 10.16.0 (generated network for admin)
78 # 10.16.0 -> <external network>
79 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
80 find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
81 find /srv/salt/reclass/ -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
82
83 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
84 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
85
86 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
87
88 # Disable checkouting the model from remote repository
89 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
90 # local storage
91 reclass:
92 storage:
93 data_source:
94 engine: local
95 EOF
96
97 # Show the changes to the console
98 cd /srv/salt/reclass/; git diff
99 node_name: {{ HOSTNAME_CFG01 }}
100 retry: {count: 1, delay: 1}
101 skip_fail: false
102
103
104- description: Configure reclass
105 cmd: |
106 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
107 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
108 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;
114 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf");
115 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
159- 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
165- 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
Artem Panchenko501e67e2017-06-14 14:59:18 +0300173# Patch linux formula to workaround https://mirantis.jira.com/browse/PROD-12327
174- description:
175 cmd: salt '*' cmd.run 'wget https://raw.githubusercontent.com/saltstack/salt/2017.7/salt/templates/debian_ip/route_eth.jinja -O
176 /usr/lib/python2.7/dist-packages/salt/templates/debian_ip/route_eth.jinja'
177 node_name: {{ HOSTNAME_CFG01 }}
178 retry: {count: 1, delay: 5}
179 skip_fail: false
180
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300181# Prepare salt services and nodes settings
182- description: Run 'linux' formula on cfg01
183 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
184 -C 'I@salt:master' state.sls linux;
185 node_name: {{ HOSTNAME_CFG01 }}
186 retry: {count: 1, delay: 5}
187 skip_fail: false
188
189- description: Run 'openssh' formula on cfg01
190 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
191 -C 'I@salt:master' state.sls openssh;
192 salt --hard-crash --state-output=mixed --state-verbose=False
193 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
194 yes/' /etc/ssh/sshd_config && service ssh restart";
195 node_name: {{ HOSTNAME_CFG01 }}
196 retry: {count: 3, delay: 5}
197 skip_fail: false
198
199- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
200 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
201 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
202 node_name: {{ HOSTNAME_CFG01 }}
203 retry: {count: 1, delay: 1}
204 skip_fail: false
205
206- description: Run 'salt.master' formula on cfg01
207 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
208 -C 'I@salt:master' state.sls salt.master.service;
209 node_name: {{ HOSTNAME_CFG01 }}
210 retry: {count: 2, delay: 5}
211 skip_fail: false
212
213- description: Run 'salt' formula on cfg01 with workaround proposed in PROD-10894
214 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
215 -C 'I@salt:master' state.sls salt;
216 salt --hard-crash --state-output=mixed --state-verbose=False
217 -C 'I@salt:master' saltutil.sync_all
218 node_name: {{ HOSTNAME_CFG01 }}
219 retry: {count: 5, delay: 5}
220 skip_fail: false
221
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300222- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
223 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
224 -C 'I@salt:master' state.sls reclass
225 node_name: {{ HOSTNAME_CFG01 }}
226 retry: {count: 1, delay: 5}
227 skip_fail: false
228
229- description: Refresh pillars on all minions
230 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
231 node_name: {{ HOSTNAME_CFG01 }}
232 retry: {count: 1, delay: 5}
233 skip_fail: false
234
235- description: Sync all salt resources
236 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
237 node_name: {{ HOSTNAME_CFG01 }}
238 retry: {count: 1, delay: 5}
239 skip_fail: false
240
241- description: Show reclass-salt --top
242 cmd: reclass-salt --top
243 node_name: {{ HOSTNAME_CFG01 }}
244 retry: {count: 1, delay: 5}
245 skip_fail: false
246
247- description: Execute salt.minion.cert
248 cmd: salt-call --no-color state.sls salt.minion.cert -l info;
249 node_name: {{ HOSTNAME_CFG01 }}
250 retry: {count: 1, delay: 5}
251 skip_fail: false
252
253# Bootstrap all nodes
254
255- description: Configure linux on other nodes
256 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
257 cfg01*' state.sls linux
258 node_name: {{ HOSTNAME_CFG01 }}
259 retry: {count: 1, delay: 5}
260 skip_fail: false
261
262- description: Configure openssh on all nodes
263 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
264 cfg01*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
265 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
266 yes/' /etc/ssh/sshd_config && service ssh restart"
267 node_name: {{ HOSTNAME_CFG01 }}
268 retry: {count: 1, delay: 5}
269 skip_fail: false
270
271- description: Configure salt.minion on other nodes
272 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
273 cfg01*' state.sls salt.minion
274 node_name: {{ HOSTNAME_CFG01 }}
275 retry: {count: 3, delay: 5}
276 skip_fail: false
277
278- description: Check salt minion versions on slaves
279 cmd: salt '*' test.version
280 node_name: {{ HOSTNAME_CFG01 }}
281 retry: {count: 1, delay: 5}
282 skip_fail: false
283
284- description: Check salt top states on nodes
285 cmd: salt '*' state.show_top
286 node_name: {{ HOSTNAME_CFG01 }}
287 retry: {count: 1, delay: 5}
288 skip_fail: false
289
290- description: Configure ntp and rsyslog on nodes
291 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog
292 node_name: {{ HOSTNAME_CFG01 }}
293 retry: {count: 1, delay: 10}
294 skip_fail: false