-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy-with-upgrade.sh
executable file
·64 lines (54 loc) · 1.91 KB
/
deploy-with-upgrade.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
#!/bin/bash
#
# Deploy an Openshift cluster by running the Ansible Playbooks.
#
# If called with no args, the initial user is assumed to be "admin",
# and a password is generated.
#
# Optional args: (intended to allow the test pipeline to supply known credentials)
# $1 - username of the admin user
# $2 - password for the admin user
# $3 - username of an additional user
# $4 - password for the additional user
#
# If $1 is supplied, $2 must be supplied.
# if $3 is supplied, $4 must also be supplied.
# All optional args are positional.
#
# TODO: merge with deploy-openshift.sh
PRIVKEY_ARG=''
if [[ -f ~/id_rsa_jenkins ]] ; then
PRIVKEY_ARG='--private-key ~/id_rsa_jenkins'
fi
if [[ "$1" == "" && "$2" == "" ]]; then
ADMIN_USER="admin"
ADMIN_PASSWORD=$(openssl rand -base64 20 | cut -d= -f1)
else
ADMIN_USER=$1
ADMIN_PASSWORD=$2
fi
echo "SHELL [run sanity tests] ..."
./sanity_tests.sh
if [[ $? -ne 0 ]]; then
echo "FATAL ERROR. Cannot deploy"
exit 1
fi
# Store the password
echo "SHELL [store and encrypt admin password] ..."
echo "${ADMIN_USER}:${ADMIN_PASSWORD}" > /home/cloud-user/passwords.txt;
# Turn the plain-text password into an htpasswd password
ansible -i localhost, localhost -c local -m htpasswd -a "path=./tmp_htpasswd name=${ADMIN_USER} password=${ADMIN_PASSWORD}"
# Store the encrypted password in the env, so the initialisation role can read it.
export OPENSHIFT_PASSWORD=$(cut -d: -f2 tmp_htpasswd)
rm tmp_htpasswd
# Build the openshift-ansible-hosts file for use in the next play,
# and install bind-utils
ansible-playbook -i localhost, -c local bastion.yml
# Perform the deployment
ansible-playbook $PRIVKEY_ARG -i openshift-ansible-hosts site.yml
# Create an additional user if $3 and $4 are supplied
if [[ "$3" != "" && "$4" != "" ]]; then
echo "SHELL [create secondary user] ..."
(cd tools; ./create-user.sh "$3" "$4")
echo "$3:$4" >> /home/cloud-user/passwords.txt
fi