forked from sabre1041/managing-ocp-install-beyond
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.sh
170 lines (152 loc) · 4.86 KB
/
launch.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
#!/bin/bash
# MIT License
#
# Copyright (c) 2018 Miguel Pérez Colino <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# Helper script to prepare Ansible Tower to deploy OpenShift Container Platform
# on AWS
#
set -euo pipefail
# Directory of this script
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Set default quiet var value, to make verifications work
QUIET=0
# Our config file
SECRETS_FILE='./my_secrets.yml'
# Assign log file for ansible
LOGS_DIR="${DIR}/logs/"
if [ ! -d ${LOGS_DIR} ]; then
mkdir -p ${LOGS_DIR}
fi
ANSIBLE_LOG_PATH="${LOGS_DIR}/ansible-$(date +%F_%T).log"
export ANSIBLE_LOG_PATH
function display_help {
echo "./$(basename "$0") [ -s | --secrets FILE ] [ -q | --quiet ] [ -h | --help | --vpc-keypair | --lab | --teardown | --redeploy | --clear-logs ] [ OPTIONAL ANSIBLE OPTIONS ]
Helper script to deploy infrastructure and OpenShift on Google Cloud Platform
Where:
-s | --secrets FILE Provide custom config file, must be relative
to the 'ansible' directory. Default is '../config.yaml'
-q | --quiet Don't ask for confirmations
-h | --help Display this help text
--vpc-keypair Create VPC and Keypair (prereq to launch the lab)
--lab Deply lab infrastructure: Tower, OpenShift
--teardown Teardown Tower, OpenShift and the infrastructure.
Warning: you will loose all your data
--redeploy Teardown Tower, OpenShift, theinfrastructure and deploy
it again. Warning: you will loose all your data
--clear-logs Delete all Ansible logs created by this script
If no action option is specified, the script will create the infrastructure
and deploy OpenShift on top of it.
OPTIONAL ANSIBLE OPTIONS All other options following the options mentioned
above will be passed directly to the Ansible. For
example, you can override any Ansible variable with:
./$(basename "$0") -e openshift_debug_level=4"
}
# Ask user for confirmation. First parameter is message
function ask_for_confirmation {
if [ $QUIET -eq 1 ]; then
return 0
fi
read -p "${1} [y/N] " yn
case $yn in
[Yy]* )
return 0
;;
* )
exit 1
;;
esac
}
# Run given playbook (1. param). All other parameters
# are passed directly to Ansible.
function run_playbook {
playbook="$1"
shift
pushd "${DIR}"
ansible-playbook -e "@${SECRETS_FILE}" $@ "$playbook"
popd
}
# Teardown infrastructure
function teardown {
ask_for_confirmation 'Are you sure you want to destroy OpenShift and the infrastructure? You will loose all your data.'
run_playbook aws_lab_terminate.yml "$@"
}
# Creates VPC and Keypair
function vpc-keypair {
echo "AWS VPC and Keypair setup"
run_playbook aws_vpc_keypair.yml "-vvv $@"
echo "--- Update subnet-id in ${SECRETS_FILE} ---"
echo "--- Move private key to username ---"
echo 'mv aws-private.pem <username>.pem '
echo "--- Add key to agent ---"
echo 'eval `ssh-agent` && ssh-add ./<username>.pem'
}
# Main function which creates infrastructure and deploys OCP
function lab {
echo "Lab Launch"
run_playbook aws_lab_launch.yml "$@"
}
while true; do
case ${1:-} in
-s | --secrets )
shift
SECRETS_FILE="${1}"
shift
;;
-q | --quiet )
QUIET=1
shift
;;
-h | --help )
display_help
exit 0
;;
--lab )
shift
lab "$@"
exit 0
;;
--vpc-keypair )
shift
vpc-keypair "$@"
exit 0
;;
--teardown )
shift
teardown "$@"
exit 0
;;
--redeploy )
shift
teardown "$@"
main "$@"
exit 0
;;
--clear-logs )
rm -f "${LOGS_DIR}"/ansible-*.log
exit 0
;;
* )
display_help
exit 0
;;
esac
done