-
Notifications
You must be signed in to change notification settings - Fork 24
/
prepare.sh
executable file
·88 lines (72 loc) · 2.31 KB
/
prepare.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
#! /bin/bash
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )
# Check number of parameters
if [ "$#" -lt 2 ]; then
echo "Usage: $0 -i <inventory file> [other ansible-playbook parameters]"
exit 1
fi
SKIP_INSTALL="False"
# Parse parameters
PARAMS=""
while (( "$#" )); do
case "$1" in
-i)
INVENTORY_FILE_PARAM=$2
shift 2
;;
--skip-install)
SKIP_INSTALL="True"
shift
;;
*) # preserve remaining arguments
PARAMS="$PARAMS $1"
shift
;;
esac
done
# Set remaining parameters
eval set -- "$PARAMS"
if [ ! -e $INVENTORY_FILE_PARAM ]; then
echo "Usage: $0 -i <inventory file> [other ansible-playbook parameters]"
echo "Available inventory files are:"
find ./inventory/ -name "*.inv"
exit 1
fi
if [ -z $pull_secret_file ];then
pull_secret_file="/tmp/ocp_pullsecret.json"
fi
if [ ! -e $pull_secret_file ];then
echo "Pull secret file $pull_secret_file does not exist, please create the file or set the pull_secret_file environment variable to point to the file that holds the pull secret."
exit 1
fi
if [ -z $ocp_admin_password ];then
echo 'OpenShift ocadmin administrator password (ocp_admin_password):'
read -s ocp_admin_password
if [ -z $ocp_admin_password ];then
echo "Error: OpenShift administrator password. OpenShift administrator password environment variable ocp_admin_password or entered at prompt"
exit 1
fi
fi
if [ -z $root_password ];then
echo 'Root password, leave blank if password-less SSH has already been configured (root_password):'
read -s root_password
if [ -z $root_password ];then
echo "Assuming password-less SSH has been configured on all nodes in the cluster and that inventory file has been adjusted accordingly."
fi
fi
# Echo extra parameters (if any)
[[ ! -z "$@" ]] && echo "Extra parameters passed to ansible-playbook: $@"
pushd $SCRIPT_DIR > /dev/null
# Run ansible playbook
inventory_file=$(realpath $INVENTORY_FILE_PARAM)
ansible-playbook -i $inventory_file playbooks/ocp4.yaml \
-e ansible_ssh_pass=$root_password \
-e ocp_admin_password=$ocp_admin_password \
-e pull_secret_file=$pull_secret_file \
-e script_dir=$SCRIPT_DIR \
-e inventory_file=$inventory_file \
-e SKIP_INSTALL=$SKIP_INSTALL \
"$@"
ANSIBLE_EXIT_CODE=$?
popd > /dev/null
exit $ANSIBLE_EXIT_CODE