blob: 0cb85cbb76008a574ab34b6998974c25f8aaed2e [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') %}
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 %}
Sergii Golovatiuk5b659d42017-05-26 17:38:06 +020013{% 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')) %}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030015
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]) %}
18
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +030019# Install salt to the config node
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030020- description: Installing salt master on cfg01
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +030021 cmd: apt-get install -y reclass git; apt-get install -y salt-master
Sergii Golovatiukc504a392017-05-22 21:41:06 +020022 node_name: {{ HOSTNAME_CFG01 }}
23 retry: {count: 1, delay: 1}
24 skip_fail: false
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030025
26- 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;
Matthew Mosesohnd0632b82017-05-30 17:51:30 +030048 for server in github.com; do
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030049 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
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030060- description: Clone reclass models with submodules
61 cmd: |
62 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
63 git clone -b {{ SALT_MODELS_COMMIT }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030064 mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030065 node_name: {{ HOSTNAME_CFG01 }}
66 retry: {count: 1, delay: 1}
67 skip_fail: false
68
69- description: Configure reclass
70 cmd: |
71 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Tatyana Leontovicheed70d72017-05-25 16:32:17 +030072 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030073 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
74 which wget > /dev/null || (apt-get update; apt-get install -y wget);
75 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
76 wget -O - "${FORMULA_GPG}" | apt-key add -;
77 apt-get clean; apt-get update;
78 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovicheed70d72017-05-25 16:32:17 +030079 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 +030080 echo -e "\nInstalling all required salt formulas\n";
81 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
82 for formula_service in "${formula_services[@]}"; do
83 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
84 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
85 done;
86 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
87 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
88 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
89
90 cat << 'EOF' >> /etc/reclass/reclass-config.yml
91 storage_type: yaml_fs
92 pretty_print: True
93 output: yaml
94 inventory_base_uri: /srv/salt/reclass
95 EOF
96 node_name: {{ HOSTNAME_CFG01 }}
97 retry: {count: 1, delay: 1}
98 skip_fail: false
99
100- description: Restart salt-master service
101 cmd: |
102 systemctl restart salt-master;
103 node_name: {{ HOSTNAME_CFG01 }}
104 retry: {count: 1, delay: 5}
105 skip_fail: false
106
107{% for ssh in config.underlay.ssh %}
108- description: Configure salt-minion on {{ ssh['node_name'] }}
109 cmd: |
110 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
111 cat << "EOF" >> /etc/salt/minion.d/minion.conf
112 id: {{ ssh['node_name'] }}
113 master: {{ config.salt.salt_master_host }}
114 EOF
115 eatmydata apt-get install -y salt-minion;
116 echo "Check for system info and metadata availability ...";
117 salt-call --no-color grains.items;
118 salt-call --no-color pillar.items;
119 node_name: {{ ssh['node_name'] }}
120 retry: {count: 1, delay: 1}
121 skip_fail: false
122{% endfor %}
123
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300124- description: Accept salt keys from all the nodes
125 cmd: salt-key -A -y
126 node_name: {{ HOSTNAME_CFG01 }}
127 retry: {count: 1, delay: 5}
128 skip_fail: true
129
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300130- description: Configure salt adoptors on cfg01
131 cmd: |
132 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
133 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
134 node_name: {{ HOSTNAME_CFG01 }}
135 retry: {count: 1, delay: 1}
136 skip_fail: false
137
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300138# Prepare salt services and nodes settings
139- description: Run 'linux' formula on cfg01
140 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
141 -C 'I@salt:master' state.sls linux;
142 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk17ef1492017-05-29 19:54:03 +0200143 retry: {count: 3, delay: 5}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300144 skip_fail: false
145
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300146- description: Run 'openssh' formula on cfg01
147 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
148 -C 'I@salt:master' state.sls openssh;
149 salt --hard-crash --state-output=mixed --state-verbose=False
150 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
151 yes/' /etc/ssh/sshd_config && service ssh restart";
152 node_name: {{ HOSTNAME_CFG01 }}
153 retry: {count: 3, delay: 5}
154 skip_fail: false
155
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300156- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
157 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
158 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
159 node_name: {{ HOSTNAME_CFG01 }}
160 retry: {count: 1, delay: 1}
161 skip_fail: false
162
163- description: Run 'salt.master' formula on cfg01
164 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
165 -C 'I@salt:master' state.sls salt.master.service;
166 node_name: {{ HOSTNAME_CFG01 }}
167 retry: {count: 2, delay: 5}
168 skip_fail: false
169
170- description: Run 'salt' formula on cfg01 with workaround proposed in PROD-10894
171 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
172 -C 'I@salt:master' state.sls salt;
173 salt --hard-crash --state-output=mixed --state-verbose=False
174 -C 'I@salt:master' saltutil.sync_all
175 node_name: {{ HOSTNAME_CFG01 }}
176 retry: {count: 5, delay: 5}
177 skip_fail: false
178
179- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
180 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
181 -C 'I@salt:master' state.sls reclass
182 node_name: {{ HOSTNAME_CFG01 }}
183 retry: {count: 1, delay: 5}
184 skip_fail: false
185
186- description: Refresh pillars on all minions
187 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
188 node_name: {{ HOSTNAME_CFG01 }}
189 retry: {count: 1, delay: 5}
190 skip_fail: false
191
192- description: Sync all salt resources
193 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
194 node_name: {{ HOSTNAME_CFG01 }}
195 retry: {count: 1, delay: 5}
196 skip_fail: false
197
Sergii Golovatiuk5b659d42017-05-26 17:38:06 +0200198- description: Show reclass-salt --top
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300199 cmd: reclass-salt --top
200 node_name: {{ HOSTNAME_CFG01 }}
201 retry: {count: 1, delay: 5}
202 skip_fail: false
203
204- description: Execute salt.minion.cert
205 cmd: salt-call --no-color state.sls salt.minion.cert -l info;
206 node_name: {{ HOSTNAME_CFG01 }}
207 retry: {count: 1, delay: 5}
208 skip_fail: false
209
210# Bootstrap all nodes
211
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +0300212- description: Configure linux on other nodes
213 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Sergii Golovatiuk5b659d42017-05-26 17:38:06 +0200214 cfg01* and not mon*' state.sls linux
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300215 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk17ef1492017-05-29 19:54:03 +0200216 retry: {count: 3, delay: 5}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300217 skip_fail: false
218
Sergii Golovatiuk5b659d42017-05-26 17:38:06 +0200219- description: Configure linux on mon nodes
220 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'mon*' state.sls linux
221 node_name: {{ HOSTNAME_CFG01 }}
222 retry: {count: 2, delay: 5}
223 skip_fail: false
224
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300225- description: Configure openssh on all nodes
226 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +0300227 cfg01*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300228 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
229 yes/' /etc/ssh/sshd_config && service ssh restart"
230 node_name: {{ HOSTNAME_CFG01 }}
231 retry: {count: 1, delay: 5}
232 skip_fail: false
233
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +0300234- description: Configure salt.minion on other nodes
235 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
236 cfg01*' state.sls salt.minion
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300237 node_name: {{ HOSTNAME_CFG01 }}
238 retry: {count: 3, delay: 5}
239 skip_fail: false
240
241- description: Check salt minion versions on slaves
242 cmd: salt '*' test.version
243 node_name: {{ HOSTNAME_CFG01 }}
244 retry: {count: 1, delay: 5}
245 skip_fail: false
246
247- description: Check salt top states on nodes
248 cmd: salt '*' state.show_top
249 node_name: {{ HOSTNAME_CFG01 }}
250 retry: {count: 1, delay: 5}
251 skip_fail: false
252
253- description: Configure ntp and rsyslog on nodes
254 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog
255 node_name: {{ HOSTNAME_CFG01 }}
256 retry: {count: 1, delay: 10}
257 skip_fail: false