blob: fa459404c45f1d0dee0939a1e0fbfa2514ae0c2c [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
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
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +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 %}
Sergii Golovatiukf03899c2017-05-30 12:12:00 +020017{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('public-pool01', '192.168.10.0/24')) %}
18{% 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 +030019
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
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +030023# Install salt to the config node
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030024- description: Installing salt master on cfg01
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +030025 cmd: apt-get install -y reclass git; apt-get install -y salt-master
Sergii Golovatiukc504a392017-05-22 21:41:06 +020026 node_name: {{ HOSTNAME_CFG01 }}
27 retry: {count: 1, delay: 1}
28 skip_fail: false
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030029
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;
Matthew Mosesohnd0632b82017-05-30 17:51:30 +030052 for server in github.com; do
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030053 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
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030064- description: Clone reclass models with submodules
65 cmd: |
66 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Valentyn Yakovlev08acf9f2017-06-07 14:02:36 +030067 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 %}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030072 mkdir -p /srv/salt/reclass/classes/service;
Sergii Golovatiukf03899c2017-05-30 12:12:00 +020073
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 find /srv/salt/reclass/ -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
88
89 # Disable checkouting the model from remote repository
90 cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
91 # local storage
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +020092 reclass:
93 storage:
94 data_source:
95 engine: local
Sergii Golovatiukf03899c2017-05-30 12:12:00 +020096 EOF
97
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030098 node_name: {{ HOSTNAME_CFG01 }}
99 retry: {count: 1, delay: 1}
100 skip_fail: false
101
102- description: Configure reclass
103 cmd: |
104 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Tatyana Leontovicheed70d72017-05-25 16:32:17 +0300105 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300106 FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg};
107 which wget > /dev/null || (apt-get update; apt-get install -y wget);
108 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
109 wget -O - "${FORMULA_GPG}" | apt-key add -;
110 apt-get clean; apt-get update;
111 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich644446f2017-06-08 13:43:36 +0300112 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 +0300113 echo -e "\nInstalling all required salt formulas\n";
114 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
115 for formula_service in "${formula_services[@]}"; do
116 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
117 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
118 done;
119 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
120 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
121 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
122
123 cat << 'EOF' >> /etc/reclass/reclass-config.yml
124 storage_type: yaml_fs
125 pretty_print: True
126 output: yaml
127 inventory_base_uri: /srv/salt/reclass
128 EOF
129 node_name: {{ HOSTNAME_CFG01 }}
130 retry: {count: 1, delay: 1}
131 skip_fail: false
132
133- description: Restart salt-master service
134 cmd: |
135 systemctl restart salt-master;
136 node_name: {{ HOSTNAME_CFG01 }}
137 retry: {count: 1, delay: 5}
138 skip_fail: false
139
140{% for ssh in config.underlay.ssh %}
141- description: Configure salt-minion on {{ ssh['node_name'] }}
142 cmd: |
143 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
144 cat << "EOF" >> /etc/salt/minion.d/minion.conf
145 id: {{ ssh['node_name'] }}
146 master: {{ config.salt.salt_master_host }}
147 EOF
148 eatmydata apt-get install -y salt-minion;
149 echo "Check for system info and metadata availability ...";
Sergii Golovatiukf648ad42017-06-23 13:39:11 +0200150 salt-call --hard-crash --no-color grains.items;
151 salt-call --hard-crash --no-color pillar.items;
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300152 node_name: {{ ssh['node_name'] }}
153 retry: {count: 1, delay: 1}
154 skip_fail: false
155{% endfor %}
156
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300157- description: Accept salt keys from all the nodes
158 cmd: salt-key -A -y
159 node_name: {{ HOSTNAME_CFG01 }}
160 retry: {count: 1, delay: 5}
161 skip_fail: true
162
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300163- description: Configure salt adoptors on cfg01
164 cmd: |
165 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
166 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
167 node_name: {{ HOSTNAME_CFG01 }}
168 retry: {count: 1, delay: 1}
169 skip_fail: false
170
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300171# Prepare salt services and nodes settings
172- description: Run 'linux' formula on cfg01
173 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
174 -C 'I@salt:master' state.sls linux;
175 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk17ef1492017-05-29 19:54:03 +0200176 retry: {count: 3, delay: 5}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300177 skip_fail: false
178
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300179- description: Run 'openssh' formula on cfg01
180 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
181 -C 'I@salt:master' state.sls openssh;
182 salt --hard-crash --state-output=mixed --state-verbose=False
183 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
184 yes/' /etc/ssh/sshd_config && service ssh restart";
185 node_name: {{ HOSTNAME_CFG01 }}
186 retry: {count: 3, delay: 5}
187 skip_fail: false
188
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300189- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
190 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
191 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
192 node_name: {{ HOSTNAME_CFG01 }}
193 retry: {count: 1, delay: 1}
194 skip_fail: false
195
196- description: Run 'salt.master' formula on cfg01
197 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200198 -C 'I@salt:master' state.sls salt.master;
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300199 node_name: {{ HOSTNAME_CFG01 }}
200 retry: {count: 2, delay: 5}
201 skip_fail: false
202
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300203- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
204 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
205 -C 'I@salt:master' state.sls reclass
206 node_name: {{ HOSTNAME_CFG01 }}
207 retry: {count: 1, delay: 5}
208 skip_fail: false
209
210- description: Refresh pillars on all minions
211 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
212 node_name: {{ HOSTNAME_CFG01 }}
213 retry: {count: 1, delay: 5}
214 skip_fail: false
215
Sergii Golovatiuk5b659d42017-05-26 17:38:06 +0200216- description: Show reclass-salt --top
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300217 cmd: reclass-salt --top
218 node_name: {{ HOSTNAME_CFG01 }}
219 retry: {count: 1, delay: 5}
220 skip_fail: false
221
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200222- description: Sync all salt resources
223 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300224 node_name: {{ HOSTNAME_CFG01 }}
225 retry: {count: 1, delay: 5}
226 skip_fail: false
227
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200228- description: Configure linux on master
229 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
230 -C 'I@salt:master' state.sls 'linux.system'
231 node_name: {{ HOSTNAME_CFG01 }}
232 retry: {count: 1, delay: 5}
233 skip_fail: false
234
235- description: Configure minion on master
Sergii Golovatiukf648ad42017-06-23 13:39:11 +0200236 cmd: salt-call --hard-crash -l debug state.sls 'salt.minion'
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200237 node_name: {{ HOSTNAME_CFG01 }}
238 retry: {count: 3, delay: 10}
239 skip_fail: false
240
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300241# Bootstrap all nodes
242
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +0300243- description: Configure linux on other nodes
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200244 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
245 -C 'I@linux:system' state.sls 'linux'
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300246 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk17ef1492017-05-29 19:54:03 +0200247 retry: {count: 3, delay: 5}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300248 skip_fail: false
249
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300250- description: Configure openssh on all nodes
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200251 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
252 -C 'I@linux:system' state.sls openssh;
253 salt --hard-crash --state-output=mixed --state-verbose=False
254 -C 'I@linux:system' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
255 yes/' /etc/ssh/sshd_config && service ssh reload"
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300256 node_name: {{ HOSTNAME_CFG01 }}
257 retry: {count: 1, delay: 5}
258 skip_fail: false
259
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200260- description: Configure salt.minion on all nodes
261 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
262 -C 'I@linux:system' state.sls salt.minion
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300263 node_name: {{ HOSTNAME_CFG01 }}
264 retry: {count: 3, delay: 5}
265 skip_fail: false
266
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200267- description: Configure ntp and rsyslog on nodes
268 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
269 -C 'I@linux:system' state.sls ntp,rsyslog
270 node_name: {{ HOSTNAME_CFG01 }}
271 retry: {count: 1, delay: 10}
272 skip_fail: false
273
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300274- description: Check salt minion versions on slaves
275 cmd: salt '*' test.version
276 node_name: {{ HOSTNAME_CFG01 }}
277 retry: {count: 1, delay: 5}
278 skip_fail: false
279
280- description: Check salt top states on nodes
281 cmd: salt '*' state.show_top
282 node_name: {{ HOSTNAME_CFG01 }}
283 retry: {count: 1, delay: 5}
284 skip_fail: false