forked from IBM-ICP4D/cloud-pak-ocp-4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm_create.sh
executable file
·65 lines (56 loc) · 1.5 KB
/
vm_create.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
#! /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
# Parse parameters
PARAMS=""
while (( "$#" )); do
case "$1" in
-i)
INVENTORY_FILE_PARAM=$2
shift 2
;;
*) # 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 "$vc_user" ];then
echo
echo 'vCenter user:'
read vc_user
if [ -z "$vc_user" ];then
echo "Error: vCenter user. vCenter user environment variable vc_user not set or entered at prompt"
exit 1
fi
fi
if [ -z "$vc_password" ];then
echo
echo 'vCenter password:'
read -s vc_password
if [ -z "$vc_password" ];then
echo "Error: vCenter password. vCenter password environment variable vc_password not set or entered at prompt"
exit 1
fi
fi
# Echo extra parameters (if any)
[[ ! -z "$@" ]] && echo "Extra parameters passed to ansible-playbook: $@"
# Run ansible playbook
inventory_file=$(realpath $INVENTORY_FILE_PARAM)
ansible-playbook -i $inventory_file playbooks/ocp4_vm_create.yaml \
-e vc_user="$vc_user" \
-e vc_password="$vc_password" \
-e inventory_file=$inventory_file \
"$@"