blob: faa7d0dcc5ec6f7873e7b7bc8ba1576f5858805c [file] [log] [blame]
Illia Polliul2a2b6d12017-05-29 17:05:11 +02001{% from 'virtual-mcp10-contrail/underlay.yaml' import HOSTNAME_CFG01 with context %}
2{% from 'virtual-mcp10-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
Illia Polliul2a2b6d12017-05-29 17:05:11 +02006
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02007{% import 'shared-salt.yaml' as SHARED with context %}
Illia Polliul2a2b6d12017-05-29 17:05:11 +02008
9# Install salt to the config node
Illia Polliul2a2b6d12017-05-29 17:05:11 +020010- description: Installing salt master on cfg01
Illia Polliulea26c1e2017-06-10 14:13:51 +020011 cmd: apt-get install -y reclass git; apt-get install -y salt-master
Illia Polliul2a2b6d12017-05-29 17:05:11 +020012 node_name: {{ HOSTNAME_CFG01 }}
13 retry: {count: 1, delay: 1}
14 skip_fail: false
15
Illia Polliul2a2b6d12017-05-29 17:05:11 +020016- description: Configure salt-master on cfg01
17 cmd: |
18 cat << 'EOF' >> /etc/salt/master.d/master.conf
19 file_roots:
20 base:
21 - /usr/share/salt-formulas/env
22 pillar_opts: False
23 open_mode: True
24 reclass: &reclass
25 storage_type: yaml_fs
26 inventory_base_uri: /srv/salt/reclass
27 ext_pillar:
28 - reclass: *reclass
29 master_tops:
30 reclass: *reclass
31 EOF
32 node_name: {{ HOSTNAME_CFG01 }}
33 retry: {count: 1, delay: 1}
34 skip_fail: false
35
36- description: Configure GIT settings and certificates
37 cmd: touch /root/.git_trusted_certs.pem;
Illia Polliulea26c1e2017-06-10 14:13:51 +020038 for server in github.com; do
Illia Polliul2a2b6d12017-05-29 17:05:11 +020039 openssl s_client -showcerts -connect $server:443 </dev/null
40 | openssl x509 -outform PEM
41 >> /root/.git_trusted_certs.pem;
42 done;
43 HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
44 HOME=/root git config --global user.email "tcp-qa@example.com";
45 HOME=/root git config --global user.name "TCP QA";
46 node_name: {{ HOSTNAME_CFG01 }}
47 retry: {count: 1, delay: 1}
48 skip_fail: false
49
Illia Polliul2a2b6d12017-05-29 17:05:11 +020050- description: Clone reclass models with submodules
51 cmd: |
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020052{{ SHARED.MACRO_CLONE_RECLASS_MODELS() }}
Illia Polliulea26c1e2017-06-10 14:13:51 +020053 find /srv/salt/reclass/ -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
Sergii Golovatiuk7fa4ffe2017-08-03 11:05:36 +020054 # Show the changes to the console
55 cd /srv/salt/reclass/; git diff
Illia Polliul2a2b6d12017-05-29 17:05:11 +020056 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};
Illia Polliul2a2b6d12017-05-29 17:05:11 +020065 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;
Illia Polliulea26c1e2017-06-10 14:13:51 +020070 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch");
Illia Polliul2a2b6d12017-05-29 17:05:11 +020071 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
91- description: Restart salt-master service
92 cmd: |
93 systemctl restart salt-master;
94 node_name: {{ HOSTNAME_CFG01 }}
95 retry: {count: 1, delay: 5}
96 skip_fail: false
97
98{% for ssh in config.underlay.ssh %}
99- description: Configure salt-minion on {{ ssh['node_name'] }}
100 cmd: |
101 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
102 cat << "EOF" >> /etc/salt/minion.d/minion.conf
103 id: {{ ssh['node_name'] }}
104 master: {{ config.salt.salt_master_host }}
105 EOF
106 eatmydata apt-get install -y salt-minion;
107 echo "Check for system info and metadata availability ...";
Sergii Golovatiuk7fa4ffe2017-08-03 11:05:36 +0200108 salt-call --hard-crash --no-color grains.items;
109 salt-call --hard-crash --no-color pillar.items;
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200110 node_name: {{ ssh['node_name'] }}
111 retry: {count: 1, delay: 1}
112 skip_fail: false
113{% endfor %}
114
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200115- description: Accept salt keys from all the nodes
116 cmd: salt-key -A -y
117 node_name: {{ HOSTNAME_CFG01 }}
118 retry: {count: 1, delay: 5}
119 skip_fail: true
120
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200121- description: Configure salt adoptors on cfg01
122 cmd: |
123 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
124 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
125 node_name: {{ HOSTNAME_CFG01 }}
126 retry: {count: 1, delay: 1}
127 skip_fail: false
128
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200129# Prepare salt services and nodes settings
130- description: Run 'linux' formula on cfg01
131 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
132 -C 'I@salt:master' state.sls linux;
133 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk7fa4ffe2017-08-03 11:05:36 +0200134 retry: {count: 2, delay: 5}
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200135 skip_fail: false
136
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200137- description: Run 'openssh' formula on cfg01
138 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
139 -C 'I@salt:master' state.sls openssh;
140 salt --hard-crash --state-output=mixed --state-verbose=False
141 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
142 yes/' /etc/ssh/sshd_config && service ssh restart";
143 node_name: {{ HOSTNAME_CFG01 }}
144 retry: {count: 3, delay: 5}
145 skip_fail: false
146
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200147- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
148 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
149 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
150 node_name: {{ HOSTNAME_CFG01 }}
151 retry: {count: 1, delay: 1}
152 skip_fail: false
153
154- description: Run 'salt.master' formula on cfg01
Sergii Golovatiuk7fa4ffe2017-08-03 11:05:36 +0200155 cmd: timeout 120 salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
Illia Polliulea26c1e2017-06-10 14:13:51 +0200156 -C 'I@salt:master' state.sls salt.master;
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200157 node_name: {{ HOSTNAME_CFG01 }}
158 retry: {count: 2, delay: 5}
159 skip_fail: false
160
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200161- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
162 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
163 -C 'I@salt:master' state.sls reclass
164 node_name: {{ HOSTNAME_CFG01 }}
165 retry: {count: 1, delay: 5}
166 skip_fail: false
167
168- description: Refresh pillars on all minions
169 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
170 node_name: {{ HOSTNAME_CFG01 }}
171 retry: {count: 1, delay: 5}
172 skip_fail: false
173
Illia Polliulea26c1e2017-06-10 14:13:51 +0200174- description: Show reclass-salt --top
175 cmd: reclass-salt --top
176 node_name: {{ HOSTNAME_CFG01 }}
177 retry: {count: 1, delay: 5}
178 skip_fail: false
179
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200180- description: Sync all salt resources
181 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
182 node_name: {{ HOSTNAME_CFG01 }}
183 retry: {count: 1, delay: 5}
184 skip_fail: false
185
Illia Polliulea26c1e2017-06-10 14:13:51 +0200186- description: Configure linux on master
187 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
188 -C 'I@salt:master' state.sls 'linux.system'
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200189 node_name: {{ HOSTNAME_CFG01 }}
190 retry: {count: 1, delay: 5}
191 skip_fail: false
192
Illia Polliulea26c1e2017-06-10 14:13:51 +0200193- description: Configure minion on master
Sergii Golovatiuk7fa4ffe2017-08-03 11:05:36 +0200194 cmd: salt-call --hard-crash --no-color state.sls 'salt.minion'
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200195 node_name: {{ HOSTNAME_CFG01 }}
Illia Polliulea26c1e2017-06-10 14:13:51 +0200196 retry: {count: 3, delay: 10}
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200197 skip_fail: false
198
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200199# Bootstrap all nodes
200
201- description: Configure linux on other nodes
Illia Polliulea26c1e2017-06-10 14:13:51 +0200202 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
203 -C 'I@linux:system' state.sls 'linux'
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200204 node_name: {{ HOSTNAME_CFG01 }}
Illia Polliul323d7272017-05-29 18:24:28 +0200205 retry: {count: 3, delay: 5}
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200206 skip_fail: false
207
208- description: Configure openssh on all nodes
Illia Polliulea26c1e2017-06-10 14:13:51 +0200209 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
210 -C 'I@linux:system' state.sls openssh;
211 salt --hard-crash --state-output=mixed --state-verbose=False
212 -C 'I@linux:system' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
213 yes/' /etc/ssh/sshd_config && service ssh reload"
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200214 node_name: {{ HOSTNAME_CFG01 }}
215 retry: {count: 1, delay: 5}
216 skip_fail: false
217
Illia Polliulea26c1e2017-06-10 14:13:51 +0200218- description: Configure salt.minion on all nodes
219 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
220 -C 'I@linux:system' state.sls salt.minion
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200221 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk7fa4ffe2017-08-03 11:05:36 +0200222 retry: {count: 2, delay: 5}
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200223 skip_fail: false
224
Illia Polliulea26c1e2017-06-10 14:13:51 +0200225- description: Configure ntp and rsyslog on nodes
226 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
227 -C 'I@linux:system' state.sls ntp,rsyslog
228 node_name: {{ HOSTNAME_CFG01 }}
Sergii Golovatiuk7fa4ffe2017-08-03 11:05:36 +0200229 retry: {count: 2, delay: 10}
Illia Polliulea26c1e2017-06-10 14:13:51 +0200230 skip_fail: false
231
Illia Polliul2a2b6d12017-05-29 17:05:11 +0200232- description: Check salt minion versions on slaves
233 cmd: salt '*' test.version
234 node_name: {{ HOSTNAME_CFG01 }}
235 retry: {count: 1, delay: 5}
236 skip_fail: false
237
238- description: Check salt top states on nodes
239 cmd: salt '*' state.show_top
240 node_name: {{ HOSTNAME_CFG01 }}
241 retry: {count: 1, delay: 5}
242 skip_fail: false