blob: 3ca2fa7cfe19e34bce971c13992e3cff00003120 [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 %}
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') %}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +03006{% 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 %}
Sergii Golovatiukf03899c2017-05-30 12:12:00 +020014{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('public-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')) %}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030016
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;
Matthew Mosesohnd0632b82017-05-30 17:51:30 +030049 for server in github.com; do
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030050 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;
Valentyn Yakovlev08acf9f2017-06-07 14:02:36 +030064 git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
65 pushd /srv/salt/reclass && git checkout {{ SALT_MODELS_COMMIT }} && popd;
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030066 mkdir -p /srv/salt/reclass/classes/service;
Sergii Golovatiukf03899c2017-05-30 12:12:00 +020067
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' {} +
76
77 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' {} +
79
80 find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
81 find /srv/salt/reclass/ -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
82
83 # Disable checkouting the model from remote repository
84 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
85 # local storage
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +020086 reclass:
87 storage:
88 data_source:
89 engine: local
Sergii Golovatiukf03899c2017-05-30 12:12:00 +020090 EOF
91
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030092 node_name: {{ HOSTNAME_CFG01 }}
93 retry: {count: 1, delay: 1}
94 skip_fail: false
95
96- description: Configure reclass
97 cmd: |
98 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Tatyana Leontovicheed70d72017-05-25 16:32:17 +030099 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300100 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
101 which wget > /dev/null || (apt-get update; apt-get install -y wget);
102 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
103 wget -O - "${FORMULA_GPG}" | apt-key add -;
104 apt-get clean; apt-get update;
105 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich644446f2017-06-08 13:43:36 +0300106 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch");
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300107 echo -e "\nInstalling all required salt formulas\n";
108 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
109 for formula_service in "${formula_services[@]}"; do
110 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
111 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
112 done;
113 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
114 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
115 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
116
117 cat << 'EOF' >> /etc/reclass/reclass-config.yml
118 storage_type: yaml_fs
119 pretty_print: True
120 output: yaml
121 inventory_base_uri: /srv/salt/reclass
122 EOF
123 node_name: {{ HOSTNAME_CFG01 }}
124 retry: {count: 1, delay: 1}
125 skip_fail: false
126
127- description: Restart salt-master service
128 cmd: |
129 systemctl restart salt-master;
130 node_name: {{ HOSTNAME_CFG01 }}
131 retry: {count: 1, delay: 5}
132 skip_fail: false
133
134{% for ssh in config.underlay.ssh %}
135- description: Configure salt-minion on {{ ssh['node_name'] }}
136 cmd: |
137 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
138 cat << "EOF" >> /etc/salt/minion.d/minion.conf
139 id: {{ ssh['node_name'] }}
140 master: {{ config.salt.salt_master_host }}
141 EOF
142 eatmydata apt-get install -y salt-minion;
143 echo "Check for system info and metadata availability ...";
144 salt-call --no-color grains.items;
145 salt-call --no-color pillar.items;
146 node_name: {{ ssh['node_name'] }}
147 retry: {count: 1, delay: 1}
148 skip_fail: false
149{% endfor %}
150
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300151- description: Accept salt keys from all the nodes
152 cmd: salt-key -A -y
153 node_name: {{ HOSTNAME_CFG01 }}
154 retry: {count: 1, delay: 5}
155 skip_fail: true
156
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300157- description: Configure salt adoptors on cfg01
158 cmd: |
159 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
160 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
161 node_name: {{ HOSTNAME_CFG01 }}
162 retry: {count: 1, delay: 1}
163 skip_fail: false
164
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300165# Prepare salt services and nodes settings
166- description: Run 'linux' formula on cfg01
167 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
168 -C 'I@salt:master' state.sls linux;
169 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk17ef1492017-05-29 19:54:03 +0200170 retry: {count: 3, delay: 5}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300171 skip_fail: false
172
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300173- description: Run 'openssh' formula on cfg01
174 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
175 -C 'I@salt:master' state.sls openssh;
176 salt --hard-crash --state-output=mixed --state-verbose=False
177 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
178 yes/' /etc/ssh/sshd_config && service ssh restart";
179 node_name: {{ HOSTNAME_CFG01 }}
180 retry: {count: 3, delay: 5}
181 skip_fail: false
182
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300183- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
184 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
185 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
186 node_name: {{ HOSTNAME_CFG01 }}
187 retry: {count: 1, delay: 1}
188 skip_fail: false
189
190- description: Run 'salt.master' formula on cfg01
191 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200192 -C 'I@salt:master' state.sls salt.master;
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300193 node_name: {{ HOSTNAME_CFG01 }}
194 retry: {count: 2, delay: 5}
195 skip_fail: false
196
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300197- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
198 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
199 -C 'I@salt:master' state.sls reclass
200 node_name: {{ HOSTNAME_CFG01 }}
201 retry: {count: 1, delay: 5}
202 skip_fail: false
203
204- description: Refresh pillars on all minions
205 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
206 node_name: {{ HOSTNAME_CFG01 }}
207 retry: {count: 1, delay: 5}
208 skip_fail: false
209
Sergii Golovatiuk5b659d42017-05-26 17:38:06 +0200210- description: Show reclass-salt --top
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300211 cmd: reclass-salt --top
212 node_name: {{ HOSTNAME_CFG01 }}
213 retry: {count: 1, delay: 5}
214 skip_fail: false
215
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200216- description: Sync all salt resources
217 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300218 node_name: {{ HOSTNAME_CFG01 }}
219 retry: {count: 1, delay: 5}
220 skip_fail: false
221
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200222- description: Configure linux on master
223 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
224 -C 'I@salt:master' state.sls 'linux.system'
225 node_name: {{ HOSTNAME_CFG01 }}
226 retry: {count: 1, delay: 5}
227 skip_fail: false
228
229- description: Configure minion on master
230 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
231 -C 'I@salt:master' state.sls 'salt.minion'
232 node_name: {{ HOSTNAME_CFG01 }}
233 retry: {count: 3, delay: 10}
234 skip_fail: false
235
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300236# Bootstrap all nodes
237
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +0300238- description: Configure linux on other nodes
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200239 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
240 -C 'I@linux:system' state.sls 'linux'
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300241 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk17ef1492017-05-29 19:54:03 +0200242 retry: {count: 3, delay: 5}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300243 skip_fail: false
244
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300245- description: Configure openssh on all nodes
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200246 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
247 -C 'I@linux:system' state.sls openssh;
248 salt --hard-crash --state-output=mixed --state-verbose=False
249 -C 'I@linux:system' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
250 yes/' /etc/ssh/sshd_config && service ssh reload"
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300251 node_name: {{ HOSTNAME_CFG01 }}
252 retry: {count: 1, delay: 5}
253 skip_fail: false
254
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200255- description: Configure salt.minion on all nodes
256 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
257 -C 'I@linux:system' state.sls salt.minion
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300258 node_name: {{ HOSTNAME_CFG01 }}
259 retry: {count: 3, delay: 5}
260 skip_fail: false
261
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200262- description: Configure ntp and rsyslog on nodes
263 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
264 -C 'I@linux:system' state.sls ntp,rsyslog
265 node_name: {{ HOSTNAME_CFG01 }}
266 retry: {count: 1, delay: 10}
267 skip_fail: false
268
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300269- 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