blob: d186c37a8343bc1d8ee087300bed2f71ba2d66f1 [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') %}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02005# Other salt model repository parameters see in shared-salt.yaml
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +03006
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02007{% import 'shared-salt.yaml' as SHARED with context %}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +03008
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +03009# Install salt to the config node
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020010
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030011- description: Installing salt master on cfg01
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +030012 cmd: apt-get install -y reclass git; apt-get install -y salt-master
Sergii Golovatiukc504a392017-05-22 21:41:06 +020013 node_name: {{ HOSTNAME_CFG01 }}
14 retry: {count: 1, delay: 1}
15 skip_fail: false
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030016
17- description: Configure salt-master on cfg01
18 cmd: |
19 cat << 'EOF' >> /etc/salt/master.d/master.conf
20 file_roots:
21 base:
22 - /usr/share/salt-formulas/env
23 pillar_opts: False
24 open_mode: True
25 reclass: &reclass
26 storage_type: yaml_fs
27 inventory_base_uri: /srv/salt/reclass
28 ext_pillar:
29 - reclass: *reclass
30 master_tops:
31 reclass: *reclass
32 EOF
33 node_name: {{ HOSTNAME_CFG01 }}
34 retry: {count: 1, delay: 1}
35 skip_fail: false
36
37- description: Configure GIT settings and certificates
38 cmd: touch /root/.git_trusted_certs.pem;
Matthew Mosesohnd0632b82017-05-30 17:51:30 +030039 for server in github.com; do
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030040 openssl s_client -showcerts -connect $server:443 </dev/null
41 | openssl x509 -outform PEM
42 >> /root/.git_trusted_certs.pem;
43 done;
44 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
45 HOME=/root git config --global user.email "tcp-qa@example.com";
46 HOME=/root git config --global user.name "TCP QA";
47 node_name: {{ HOSTNAME_CFG01 }}
48 retry: {count: 1, delay: 1}
49 skip_fail: false
50
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030051- description: Clone reclass models with submodules
52 cmd: |
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020053{{ SHARED.MACRO_CLONE_RECLASS_MODELS() }}
Sergii Golovatiuk44a43522017-07-20 12:55:13 +020054 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Sergii Golovatiukf03899c2017-05-30 12:12:00 +020055 find /srv/salt/reclass/ -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +020056 # Show the changes to the console
57 cd /srv/salt/reclass/; git diff
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030058 node_name: {{ HOSTNAME_CFG01 }}
59 retry: {count: 1, delay: 1}
60 skip_fail: false
61
62- description: Configure reclass
63 cmd: |
64 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
obutenko89aedf82017-08-04 12:50:37 +030065 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
66 FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg};
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +030067 which wget > /dev/null || (apt-get update; apt-get install -y wget);
68 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
69 wget -O - "${FORMULA_GPG}" | apt-key add -;
70 apt-get clean; apt-get update;
71 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich644446f2017-06-08 13:43:36 +030072 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 +030073 echo -e "\nInstalling all required salt formulas\n";
74 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
75 for formula_service in "${formula_services[@]}"; do
76 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
77 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
78 done;
79 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
80 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
81 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
82
83 cat << 'EOF' >> /etc/reclass/reclass-config.yml
84 storage_type: yaml_fs
85 pretty_print: True
86 output: yaml
87 inventory_base_uri: /srv/salt/reclass
88 EOF
89 node_name: {{ HOSTNAME_CFG01 }}
90 retry: {count: 1, delay: 1}
91 skip_fail: false
92
93- description: Restart salt-master service
94 cmd: |
95 systemctl restart salt-master;
96 node_name: {{ HOSTNAME_CFG01 }}
97 retry: {count: 1, delay: 5}
98 skip_fail: false
99
100{% for ssh in config.underlay.ssh %}
101- description: Configure salt-minion on {{ ssh['node_name'] }}
102 cmd: |
103 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
104 cat << "EOF" >> /etc/salt/minion.d/minion.conf
105 id: {{ ssh['node_name'] }}
106 master: {{ config.salt.salt_master_host }}
107 EOF
108 eatmydata apt-get install -y salt-minion;
109 echo "Check for system info and metadata availability ...";
Sergii Golovatiukf648ad42017-06-23 13:39:11 +0200110 salt-call --hard-crash --no-color grains.items;
111 salt-call --hard-crash --no-color pillar.items;
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300112 node_name: {{ ssh['node_name'] }}
113 retry: {count: 1, delay: 1}
114 skip_fail: false
115{% endfor %}
116
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300117- description: Accept salt keys from all the nodes
118 cmd: salt-key -A -y
119 node_name: {{ HOSTNAME_CFG01 }}
120 retry: {count: 1, delay: 5}
121 skip_fail: true
122
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300123- description: Configure salt adoptors on cfg01
124 cmd: |
125 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
126 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
127 node_name: {{ HOSTNAME_CFG01 }}
128 retry: {count: 1, delay: 1}
129 skip_fail: false
130
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300131# Prepare salt services and nodes settings
132- description: Run 'linux' formula on cfg01
133 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
134 -C 'I@salt:master' state.sls linux;
135 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +0200136 retry: {count: 2, delay: 5}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300137 skip_fail: false
138
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300139- description: Run 'openssh' formula on cfg01
140 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
141 -C 'I@salt:master' state.sls openssh;
142 salt --hard-crash --state-output=mixed --state-verbose=False
143 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
144 yes/' /etc/ssh/sshd_config && service ssh restart";
145 node_name: {{ HOSTNAME_CFG01 }}
146 retry: {count: 3, delay: 5}
147 skip_fail: false
148
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300149- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
150 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
151 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
152 node_name: {{ HOSTNAME_CFG01 }}
153 retry: {count: 1, delay: 1}
154 skip_fail: false
155
156- description: Run 'salt.master' formula on cfg01
Dennis Dmitrievd9a4aed2017-07-27 09:17:17 +0300157 cmd: timeout 120 salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200158 -C 'I@salt:master' state.sls salt.master;
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300159 node_name: {{ HOSTNAME_CFG01 }}
160 retry: {count: 2, delay: 5}
161 skip_fail: false
162
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300163- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
164 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
165 -C 'I@salt:master' state.sls reclass
166 node_name: {{ HOSTNAME_CFG01 }}
167 retry: {count: 1, delay: 5}
168 skip_fail: false
169
170- description: Refresh pillars on all minions
171 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
172 node_name: {{ HOSTNAME_CFG01 }}
173 retry: {count: 1, delay: 5}
174 skip_fail: false
175
Sergii Golovatiuk5b659d42017-05-26 17:38:06 +0200176- description: Show reclass-salt --top
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300177 cmd: reclass-salt --top
178 node_name: {{ HOSTNAME_CFG01 }}
179 retry: {count: 1, delay: 5}
180 skip_fail: false
181
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200182- description: Sync all salt resources
183 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300184 node_name: {{ HOSTNAME_CFG01 }}
185 retry: {count: 1, delay: 5}
186 skip_fail: false
187
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200188- description: Configure linux on master
189 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
190 -C 'I@salt:master' state.sls 'linux.system'
191 node_name: {{ HOSTNAME_CFG01 }}
192 retry: {count: 1, delay: 5}
193 skip_fail: false
194
195- description: Configure minion on master
Sergii Golovatiukf648ad42017-06-23 13:39:11 +0200196 cmd: salt-call --hard-crash -l debug state.sls 'salt.minion'
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200197 node_name: {{ HOSTNAME_CFG01 }}
198 retry: {count: 3, delay: 10}
199 skip_fail: false
200
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300201# Bootstrap all nodes
202
Tatyana Leontovich508d0cb2017-05-26 15:46:24 +0300203- description: Configure linux on other nodes
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200204 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
205 -C 'I@linux:system' state.sls 'linux'
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300206 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk17ef1492017-05-29 19:54:03 +0200207 retry: {count: 3, delay: 5}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300208 skip_fail: false
209
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300210- description: Configure openssh on all nodes
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200211 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
212 -C 'I@linux:system' state.sls openssh;
213 salt --hard-crash --state-output=mixed --state-verbose=False
214 -C 'I@linux:system' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
215 yes/' /etc/ssh/sshd_config && service ssh reload"
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300216 node_name: {{ HOSTNAME_CFG01 }}
217 retry: {count: 1, delay: 5}
218 skip_fail: false
219
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200220- description: Configure salt.minion on all nodes
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +0200221 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200222 -C 'I@linux:system' state.sls salt.minion
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300223 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +0200224 retry: {count: 2, delay: 5}
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300225 skip_fail: false
226
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200227- description: Configure ntp and rsyslog on nodes
228 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
229 -C 'I@linux:system' state.sls ntp,rsyslog
230 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk01e3a2d2017-08-02 11:28:26 +0200231 retry: {count: 2, delay: 10}
Sergii Golovatiuk8f679ab2017-06-02 13:13:53 +0200232 skip_fail: false
233
Tatyana Leontovichbb6d1a72017-05-17 14:10:38 +0300234- description: Check salt minion versions on slaves
235 cmd: salt '*' test.version
236 node_name: {{ HOSTNAME_CFG01 }}
237 retry: {count: 1, delay: 5}
238 skip_fail: false
239
240- description: Check salt top states on nodes
241 cmd: salt '*' state.show_top
242 node_name: {{ HOSTNAME_CFG01 }}
243 retry: {count: 1, delay: 5}
244 skip_fail: false