blob: b2d73838b687f94e25afe34bd8df77ced31d1413 [file] [log] [blame]
Illia Polliul2a2b6d12017-05-29 17:05:11 +02001{% from 'virtual-mcp10-contrail/underlay.yaml' import HOSTNAME_CFG01 with context %}
2{% from 'virtual-mcp10-contrail/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') %}
Illia Polliul2a2b6d12017-05-29 17:05:11 +02006{% 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{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
17{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
18
19{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
20{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
21{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
22{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
23
24# Install salt to the config node
Illia Polliul2a2b6d12017-05-29 17:05:11 +020025- description: Installing salt master on cfg01
Illia Polliulea26c1e2017-06-10 14:13:51 +020026 cmd: apt-get install -y reclass git; apt-get install -y salt-master
Illia Polliul2a2b6d12017-05-29 17:05:11 +020027 node_name: {{ HOSTNAME_CFG01 }}
28 retry: {count: 1, delay: 1}
29 skip_fail: false
30
Illia Polliul2a2b6d12017-05-29 17:05:11 +020031- description: Configure salt-master on cfg01
32 cmd: |
33 cat << 'EOF' >> /etc/salt/master.d/master.conf
34 file_roots:
35 base:
36 - /usr/share/salt-formulas/env
37 pillar_opts: False
38 open_mode: True
39 reclass: &reclass
40 storage_type: yaml_fs
41 inventory_base_uri: /srv/salt/reclass
42 ext_pillar:
43 - reclass: *reclass
44 master_tops:
45 reclass: *reclass
46 EOF
47 node_name: {{ HOSTNAME_CFG01 }}
48 retry: {count: 1, delay: 1}
49 skip_fail: false
50
51- description: Configure GIT settings and certificates
52 cmd: touch /root/.git_trusted_certs.pem;
Illia Polliulea26c1e2017-06-10 14:13:51 +020053 for server in github.com; do
Illia Polliul2a2b6d12017-05-29 17:05:11 +020054 openssl s_client -showcerts -connect $server:443 </dev/null
55 | openssl x509 -outform PEM
56 >> /root/.git_trusted_certs.pem;
57 done;
58 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
59 HOME=/root git config --global user.email "tcp-qa@example.com";
60 HOME=/root git config --global user.name "TCP QA";
61 node_name: {{ HOSTNAME_CFG01 }}
62 retry: {count: 1, delay: 1}
63 skip_fail: false
64
Illia Polliul2a2b6d12017-05-29 17:05:11 +020065- description: Clone reclass models with submodules
66 cmd: |
67 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Valentyn Yakovlev08acf9f2017-06-07 14:02:36 +030068 git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
69 pushd /srv/salt/reclass && git checkout {{ SALT_MODELS_COMMIT }} && popd;
Illia Polliul2a2b6d12017-05-29 17:05:11 +020070 mkdir -p /srv/salt/reclass/classes/service;
71
72 # Replace firstly to an intermediate value to avoid intersection between
73 # already replaced and replacing networks.
74 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
75 # 192.168.10 -> 10.16.0 (generated network for admin)
76 # 10.16.0 -> <external network>
77 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
78 find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
79 find /srv/salt/reclass/ -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
80 find /srv/salt/reclass/ -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} +
81 find /srv/salt/reclass/ -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_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 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} +
86 find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {} +
87
88 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
Illia Polliulea26c1e2017-06-10 14:13:51 +020089 find /srv/salt/reclass/ -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
Illia Polliul2a2b6d12017-05-29 17:05:11 +020090
91 # Disable checkouting the model from remote repository
92 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
93 # local storage
Illia Polliulea26c1e2017-06-10 14:13:51 +020094 reclass:
95 storage:
96 data_source:
97 engine: local
Illia Polliul2a2b6d12017-05-29 17:05:11 +020098 EOF
99
Sergii Golovatiuk7fa4ffe2017-08-03 11:05:36 +0200100 # Show the changes to the console
101 cd /srv/salt/reclass/; git diff
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200102 node_name: {{ HOSTNAME_CFG01 }}
103 retry: {count: 1, delay: 1}
104 skip_fail: false
105
106- description: Configure reclass
107 cmd: |
108 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
obutenko89aedf82017-08-04 12:50:37 +0300109 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
110 FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg};
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200111 which wget > /dev/null || (apt-get update; apt-get install -y wget);
112 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
113 wget -O - "${FORMULA_GPG}" | apt-key add -;
114 apt-get clean; apt-get update;
115 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Illia Polliulea26c1e2017-06-10 14:13:51 +0200116 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch");
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200117 echo -e "\nInstalling all required salt formulas\n";
118 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
119 for formula_service in "${formula_services[@]}"; do
120 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
121 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
122 done;
123 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
124 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
125 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
126
127 cat << 'EOF' >> /etc/reclass/reclass-config.yml
128 storage_type: yaml_fs
129 pretty_print: True
130 output: yaml
131 inventory_base_uri: /srv/salt/reclass
132 EOF
133 node_name: {{ HOSTNAME_CFG01 }}
134 retry: {count: 1, delay: 1}
135 skip_fail: false
136
137- description: Restart salt-master service
138 cmd: |
139 systemctl restart salt-master;
140 node_name: {{ HOSTNAME_CFG01 }}
141 retry: {count: 1, delay: 5}
142 skip_fail: false
143
144{% for ssh in config.underlay.ssh %}
145- description: Configure salt-minion on {{ ssh['node_name'] }}
146 cmd: |
147 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
148 cat << "EOF" >> /etc/salt/minion.d/minion.conf
149 id: {{ ssh['node_name'] }}
150 master: {{ config.salt.salt_master_host }}
151 EOF
152 eatmydata apt-get install -y salt-minion;
153 echo "Check for system info and metadata availability ...";
Sergii Golovatiuk7fa4ffe2017-08-03 11:05:36 +0200154 salt-call --hard-crash --no-color grains.items;
155 salt-call --hard-crash --no-color pillar.items;
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200156 node_name: {{ ssh['node_name'] }}
157 retry: {count: 1, delay: 1}
158 skip_fail: false
159{% endfor %}
160
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200161- description: Accept salt keys from all the nodes
162 cmd: salt-key -A -y
163 node_name: {{ HOSTNAME_CFG01 }}
164 retry: {count: 1, delay: 5}
165 skip_fail: true
166
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200167- description: Configure salt adoptors on cfg01
168 cmd: |
169 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
170 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
171 node_name: {{ HOSTNAME_CFG01 }}
172 retry: {count: 1, delay: 1}
173 skip_fail: false
174
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200175# Prepare salt services and nodes settings
176- description: Run 'linux' formula on cfg01
177 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
178 -C 'I@salt:master' state.sls linux;
179 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk7fa4ffe2017-08-03 11:05:36 +0200180 retry: {count: 2, delay: 5}
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200181 skip_fail: false
182
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200183- description: Run 'openssh' formula on cfg01
184 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
185 -C 'I@salt:master' state.sls openssh;
186 salt --hard-crash --state-output=mixed --state-verbose=False
187 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
188 yes/' /etc/ssh/sshd_config && service ssh restart";
189 node_name: {{ HOSTNAME_CFG01 }}
190 retry: {count: 3, delay: 5}
191 skip_fail: false
192
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200193- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
194 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
195 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
196 node_name: {{ HOSTNAME_CFG01 }}
197 retry: {count: 1, delay: 1}
198 skip_fail: false
199
200- description: Run 'salt.master' formula on cfg01
Sergii Golovatiuk7fa4ffe2017-08-03 11:05:36 +0200201 cmd: timeout 120 salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
Illia Polliulea26c1e2017-06-10 14:13:51 +0200202 -C 'I@salt:master' state.sls salt.master;
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200203 node_name: {{ HOSTNAME_CFG01 }}
204 retry: {count: 2, delay: 5}
205 skip_fail: false
206
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200207- 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
Illia Polliulea26c1e2017-06-10 14:13:51 +0200220- description: Show reclass-salt --top
221 cmd: reclass-salt --top
222 node_name: {{ HOSTNAME_CFG01 }}
223 retry: {count: 1, delay: 5}
224 skip_fail: false
225
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200226- description: Sync all salt resources
227 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
228 node_name: {{ HOSTNAME_CFG01 }}
229 retry: {count: 1, delay: 5}
230 skip_fail: false
231
Illia Polliulea26c1e2017-06-10 14:13:51 +0200232- description: Configure linux on master
233 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
234 -C 'I@salt:master' state.sls 'linux.system'
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200235 node_name: {{ HOSTNAME_CFG01 }}
236 retry: {count: 1, delay: 5}
237 skip_fail: false
238
Illia Polliulea26c1e2017-06-10 14:13:51 +0200239- description: Configure minion on master
Sergii Golovatiuk7fa4ffe2017-08-03 11:05:36 +0200240 cmd: salt-call --hard-crash --no-color state.sls 'salt.minion'
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200241 node_name: {{ HOSTNAME_CFG01 }}
Illia Polliulea26c1e2017-06-10 14:13:51 +0200242 retry: {count: 3, delay: 10}
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200243 skip_fail: false
244
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200245# Bootstrap all nodes
246
247- description: Configure linux on other nodes
Illia Polliulea26c1e2017-06-10 14:13:51 +0200248 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
249 -C 'I@linux:system' state.sls 'linux'
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200250 node_name: {{ HOSTNAME_CFG01 }}
Illia Polliul323d7272017-05-29 18:24:28 +0200251 retry: {count: 3, delay: 5}
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200252 skip_fail: false
253
254- description: Configure openssh on all nodes
Illia Polliulea26c1e2017-06-10 14:13:51 +0200255 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
256 -C 'I@linux:system' state.sls openssh;
257 salt --hard-crash --state-output=mixed --state-verbose=False
258 -C 'I@linux:system' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
259 yes/' /etc/ssh/sshd_config && service ssh reload"
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200260 node_name: {{ HOSTNAME_CFG01 }}
261 retry: {count: 1, delay: 5}
262 skip_fail: false
263
Illia Polliulea26c1e2017-06-10 14:13:51 +0200264- description: Configure salt.minion on all nodes
265 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
266 -C 'I@linux:system' state.sls salt.minion
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200267 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk7fa4ffe2017-08-03 11:05:36 +0200268 retry: {count: 2, delay: 5}
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200269 skip_fail: false
270
Illia Polliulea26c1e2017-06-10 14:13:51 +0200271- description: Configure ntp and rsyslog on nodes
272 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
273 -C 'I@linux:system' state.sls ntp,rsyslog
274 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk7fa4ffe2017-08-03 11:05:36 +0200275 retry: {count: 2, delay: 10}
Illia Polliulea26c1e2017-06-10 14:13:51 +0200276 skip_fail: false
277
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200278- 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