blob: bfcc888dac9c3457e6eb74aa6d315ce0033d218a [file] [log] [blame]
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +03001{% from 'virtual-mcp-ocata-cicd/underlay.yaml' import HOSTNAME_CFG01 with context %}
2{% from 'virtual-mcp-ocata-cicd/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
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +03006
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02007{% import 'shared-salt.yaml' as SHARED with context %}
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +03008
9# Install salt to the config node
10
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030011- description: Installing salt master on cfg01
12 cmd: eatmydata apt-get install -y reclass git salt-master
13 node_name: {{ HOSTNAME_CFG01 }}
14 retry: {count: 1, delay: 1}
15 skip_fail: false
16
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030017- 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;
39 for server in git.tcpcloud.eu github.com; do
40 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
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030051- description: Clone reclass models with submodules
52 cmd: |
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020053{{ SHARED.MACRO_CLONE_RECLASS_MODELS() }}
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030054 # Show the changes to the console
55 cd /srv/salt/reclass/; git diff
56 node_name: {{ HOSTNAME_CFG01 }}
57 retry: {count: 1, delay: 1}
58 skip_fail: false
59
60- description: Configure reclass
61 cmd: |
62 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
obutenko89aedf82017-08-04 12:50:37 +030063 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt};
64 FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg};
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030065 which wget > /dev/null || (apt-get update; apt-get install -y wget);
66 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list;
67 wget -O - "${FORMULA_GPG}" | apt-key add -;
68 apt-get clean; apt-get update;
69 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitriev76f65462017-07-20 16:21:26 -040070 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch" "docker" "kibana");
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030071 echo -e "\nInstalling all required salt formulas\n";
72 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
73 for formula_service in "${formula_services[@]}"; do
74 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
75 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
76 done;
77 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
78 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
79 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
80
81 cat << 'EOF' >> /etc/reclass/reclass-config.yml
82 storage_type: yaml_fs
83 pretty_print: True
84 output: yaml
85 inventory_base_uri: /srv/salt/reclass
86 EOF
87 node_name: {{ HOSTNAME_CFG01 }}
88 retry: {count: 1, delay: 1}
89 skip_fail: false
90
Dennis Dmitriev9c2707e2017-07-21 13:17:53 +030091- description: "*Workaround* remove all cfg01 nodes except {{ HOSTNAME_CFG01 }} to not depend on other clusters in 'reclass --top'"
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030092 cmd: |
Dennis Dmitriev9c2707e2017-07-21 13:17:53 +030093 # Remove all other nodes except {{ HOSTNAME_CFG01 }} to not rely on them for 'reclass --top'
94 find /srv/salt/reclass/nodes/ -type f -not -name {{ HOSTNAME_CFG01 }}.yml -delete
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030095 node_name: {{ HOSTNAME_CFG01 }}
96 retry: {count: 1, delay: 5}
97 skip_fail: false
98
99- description: Show reclass-salt --top for cfg01 node
Dennis Dmitriev9c2707e2017-07-21 13:17:53 +0300100 cmd: reclass-salt --top
101 node_name: {{ HOSTNAME_CFG01 }}
102 retry: {count: 1, delay: 5}
103 skip_fail: false
104
105- description: Restart salt-master service
106 cmd: systemctl restart salt-master;
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300107 node_name: {{ HOSTNAME_CFG01 }}
108 retry: {count: 1, delay: 5}
109 skip_fail: false
110
111{%- for ssh in config.underlay.ssh %}
112- description: Configure salt-minion on {{ ssh['node_name'] }}
113 cmd: |
114 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
115 cat << "EOF" >> /etc/salt/minion.d/minion.conf
116 id: {{ ssh['node_name'] }}
117 master: {{ config.salt.salt_master_host }}
118 EOF
119 eatmydata apt-get install -y salt-minion;
120 echo "Check for system info and metadata availability ...";
121 salt-call --no-color grains.items;
122 salt-call --no-color pillar.items;
123 node_name: {{ ssh['node_name'] }}
124 retry: {count: 1, delay: 1}
125 skip_fail: false
126{%- endfor %}
127
128
129- description: Accept salt keys from all the nodes
130 cmd: salt-key -A -y
131 node_name: {{ HOSTNAME_CFG01 }}
132 retry: {count: 1, delay: 5}
133 skip_fail: true
134
135- description: Configure salt adoptors on cfg01
136 cmd: |
137 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
138 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
139 node_name: {{ HOSTNAME_CFG01 }}
140 retry: {count: 1, delay: 1}
141 skip_fail: false
142
143# Prepare salt services and nodes settings
144- description: Run 'linux' formula on cfg01
145 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
146 node_name: {{ HOSTNAME_CFG01 }}
147 retry: {count: 1, delay: 5}
148 skip_fail: false
149
150- description: Run 'openssh' formula on cfg01
151 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
152 -C 'I@salt:master' state.sls openssh;
153 salt --hard-crash --state-output=mixed --state-verbose=False
154 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
155 yes/' /etc/ssh/sshd_config && service ssh reload";
156 node_name: {{ HOSTNAME_CFG01 }}
157 retry: {count: 3, delay: 5}
158 skip_fail: false
159
160- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
161 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
162 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
163 node_name: {{ HOSTNAME_CFG01 }}
164 retry: {count: 1, delay: 1}
165 skip_fail: false
166
167- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve4cfced2017-07-27 07:31:21 +0300168 cmd: timeout 120 salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300169 node_name: {{ HOSTNAME_CFG01 }}
170 retry: {count: 2, delay: 5}
171 skip_fail: false
172
173- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
174 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
175 -C 'I@salt:master' state.sls reclass
176 node_name: {{ HOSTNAME_CFG01 }}
177 retry: {count: 1, delay: 5}
178 skip_fail: false
179
180- description: Refresh pillars on all minions
181 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
182 node_name: {{ HOSTNAME_CFG01 }}
183 retry: {count: 1, delay: 5}
184 skip_fail: false
185
186- description: Show reclass-salt --top for all generated nodes
187 cmd: reclass-salt --top
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
198- description: Configure linux on master
199 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
200 node_name: {{ HOSTNAME_CFG01 }}
201 retry: {count: 1, delay: 5}
202 skip_fail: false
203
Dennis Dmitrievf8546172017-07-20 21:57:05 +0300204- description: Configure salt.minion on master
Dennis Dmitriev980db162017-07-27 09:40:01 +0300205 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitrievf8546172017-07-20 21:57:05 +0300206 -C 'I@salt:master' state.sls salt.minion
207 node_name: {{ HOSTNAME_CFG01 }}
208 retry: {count: 3, delay: 10}
209 skip_fail: false
210
211- description: Run state 'salt' on master (for salt.api, etc)
212 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
213 -C 'I@salt:master' state.sls salt
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300214 node_name: {{ HOSTNAME_CFG01 }}
215 retry: {count: 3, delay: 10}
216 skip_fail: false
217
218# Bootstrap all nodes
219
220- description: Configure linux on other nodes
221 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls 'linux'
222 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve4cfced2017-07-27 07:31:21 +0300223 retry: {count: 3, delay: 5}
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300224 skip_fail: false
225
226- description: Configure openssh on all nodes
227 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls openssh;
228 salt --hard-crash --state-output=mixed --state-verbose=False
229 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
230 yes/' /etc/ssh/sshd_config && service ssh reload"
231 node_name: {{ HOSTNAME_CFG01 }}
232 retry: {count: 1, delay: 5}
233 skip_fail: false
234
235- description: Configure salt.minion on other nodes
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300236 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion && sleep 10
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300237 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev5b0e5f32017-07-22 11:30:26 +0300238 retry: {count: 3, delay: 15}
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300239 skip_fail: false
240
241- description: Check salt minion versions on slaves
242 cmd: salt '*' test.version
243 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300244 retry: {count: 2, delay: 5}
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300245 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 -C 'I@linux:system' state.sls ntp,rsyslog
255 node_name: {{ HOSTNAME_CFG01 }}
256 retry: {count: 1, delay: 10}
257 skip_fail: false