-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathocplabs.sh
executable file
·212 lines (160 loc) · 5.1 KB
/
ocplabs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
trap interrupt 1 2 3 6 9 15
function interrupt()
{
log error "OpenShift Enterprise v3.11 installation aborted"
exit
}
function log()
{
DATE="`date`"
COLOR=""
case "$1" in
debug)
COLOR=""
;;
info)
COLOR="\x1B[01;94m"
;;
warn)
COLOR="\x1B[01;93m"
;;
error)
COLOR="\x1B[31m"
;;
esac
echo -e "${COLOR}$DATE $1 $2\x1B[0m"
}
function show_input_info()
{
echo -e -n "\x1B[01;94m$1:\x1B[0m"
}
function show_usage() {
echo "Usage: ocplabs.sh <install|deinstall|cns-install|cns-deinstall|app-install> <parameters>"
}
function bastion_host_preparation() {
# Prepare hosts
log info "Bastion Host preparation started."
yum install -y ansible >> ocplabs.log 2>&1
cp .ansible.cfg /etc/ansible/ansible.cfg
ansible-playbook -vvv -i ocplabs-ocp-inventory.cfg ocplabs-bastion-host-setup.yaml -e "@ocplabs-ansible-variables.json" >> ocplabs.log 2>&1
ERROR_CODE=$?
if [ $ERROR_CODE -ne 0 ]; then
log error "Bastion Host preparation failed. Aborting."
exit
fi
log info "Bastion Host preparation finished."
}
function ocp_nodes_preparation() {
log info "OCP Nodes preparation started."
ansible-playbook -vvv -i ocplabs-ocp-inventory.cfg ocplabs-ocp-nodes-setup.yaml -e "@ocplabs-ansible-variables.json" >> ocplabs.log 2>&1
ERROR_CODE=$?
if [ $ERROR_CODE -ne 0 ]; then
log error "OCP Nodes preparation failed. Aborting."
exit
fi
log info "OCP Nodes preparation finished."
}
function ocp_nodes_prerequisites_check() {
log info "OCP Installation Prerequisites check started."
ansible-playbook -vvv -i ocplabs-ocp-inventory.cfg /usr/share/ansible/openshift-ansible/playbooks/prerequisites.yml >> ocplabs.log 2>&1
ERROR_CODE=$?
if [ $ERROR_CODE -ne 0 ]; then
log error "OCP Installation Prerequisites check failed. Aborting."
exit
fi
log info "OCP Installation Prerequisites check finished."
}
OPTS="$*"
MODE=unknown
for opt in $OPTS ; do
VALUE="`echo $opt | cut -d"=" -f2`"
case "$opt" in
install)
MODE=install
;;
cns-install)
MODE=cns-install
;;
deinstall)
MODE=deinstall
;;
cns-deinstall)
MODE=cns-deinstall
;;
app-install)
MODE=app-install
;;
esac
done
if [ ! -f "ocplabs-ocp-inventory.cfg" ] ; then
log error "Mandatory configuration-file ocplabs-ocp-inventory.cfg missing."
exit
fi
case "$MODE" in
install)
bastion_host_preparation
ocp_nodes_preparation
ocp_nodes_prerequisites_check
log info "Starting OpenShift Container Platform v3.11 installation."
ansible-playbook -vvv -i ocplabs-ocp-inventory.cfg /usr/share/ansible/openshift-ansible/playbooks/prerequisites.yml >> ocplabs.log 2>&1
ERROR_CODE=$?
if [ $ERROR_CODE -ne 0 ]; then
log error "Prerequisites check failed. Aborting."
exit
fi
ansible-playbook -vvv -i ocplabs-ocp-inventory.cfg /usr/share/ansible/openshift-ansible/playbooks/deploy_cluster.yml >> ocplabs.log 2>&1
ERROR_CODE=$?
if [ $ERROR_CODE -ne 0 ]; then
log error "Deployment failed. Aborting."
exit
fi
log info "Post Installation started."
ansible-playbook -vvv -i ocplabs-ocp-inventory.cfg ocplabs-ocp-nodes-post-setup.yaml >> ocplabs.log 2>&1
ERROR_CODE=$?
if [ $ERROR_CODE -ne 0 ]; then
log error "Post Installation failed. Aborting."
exit
fi
log info "Post Installation finished."
log info "Finished OpenShift Container Platform v3.11 installation."
;;
cns-install)
log info "Starting OpenShift Container Platform v3.11 CNS installation."
log info "Deployment started."
ansible-playbook -vvv -i ocplabs-cns-inventory.cfg ocplabs-cns-nodes-deinstall.yaml >> ocplabs.log 2>&1
ansible-playbook -vvv -i ocplabs-cns-inventory.cfg ocplabs-cns-nodes-setup.yaml >> ocplabs.log 2>&1
ERROR_CODE=$?
if [ $ERROR_CODE -ne 0 ]; then
log error "CNS Installation failed. Aborting."
exit
fi
log info "Finished OpenShift Container Platform v3.11 CNS installation."
;;
app-install)
log info "Starting OpenShift Container Platform v3.11 Additional Application installation."
log info "Deployment started."
ansible-playbook -vvv -i ocplabs-cns-inventory.cfg ocplabs-ocp-additional-application.yaml >> ocplabs.log 2>&1
ERROR_CODE=$?
if [ $ERROR_CODE -ne 0 ]; then
log error "Application Installation failed. Aborting."
exit
fi
log info "Finished OpenShift Container Platform v3.11 Additional Application installation."
;;
deinstall)
log info "Starting OpenShift Container Platform v3.11 deinstallation."
ansible-playbook -vvv -i ocplabs-ocp-inventory.cfg /usr/share/ansible/openshift-ansible/playbooks/adhoc/uninstall.yml >> ocplabs.log 2>&1
ansible-playbook -vvv -i ocplabs-ocp-inventory.cfg ocplabs-ocp-nodes-deinstall.yaml >> ocplabs.log 2>&1
log info "Finished OpenShift Container Platform v3.11 deinstallation."
;;
cns-deinstall)
log info "Starting OpenShift Container Platform v3.11 CNS deinstallation."
ansible-playbook -vvv -i ocplabs-cns-inventory.cfg ocplabs-cns-nodes-deinstall.yaml >> ocplabs.log 2>&1
log info "Finished OpenShift Container Platform v3.11 CNS deinstallation."
;;
*)
show_usage
exit
;;
esac