forked from google/bms-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
host-provision.sh
executable file
·111 lines (93 loc) · 2.85 KB
/
host-provision.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
#!/bin/bash
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
echo Command used:
echo "$0 $@"
echo
shopt -s nocasematch
# Check if we're using the Mac stock getopt and fail if true
out=`getopt -T`
if [ $? != 4 ]; then
echo -e "Your getopt does not support long parameters, possibly you're on a Mac, if so please install gnu-getopt with brew"
echo -e "\thttps://brewformulas.org/Gnu-getopt"
exit
fi
GETOPT_MANDATORY="instance-ip-addr:"
GETOPT_OPTIONAL="instance-ssh-user:,proxy-setup:,u01-lun:,help"
GETOPT_LONG="${GETOPT_MANDATORY},${GETOPT_OPTIONAL}"
GETOPT_SHORT="h"
INSTANCE_SSH_USER="${INSTANCE_SSH_USER:-'ansible'}"
options=$(getopt --longoptions "$GETOPT_LONG" --options "$GETOPT_SHORT" -- "$@")
[ $? -eq 0 ] || {
echo "Invalid options provided: $*"
exit 1
}
# echo "PARSED COMMAND LINE FLAGS: $options"
eval set -- "$options"
while true; do
case "$1" in
--u01-lun)
ORA_U01_LUN="$2"
shift;
;;
--proxy-setup)
ORA_PROXY_SETUP="$2"
shift;
;;
--instance-ssh-user)
INSTANCE_SSH_USER="$2"
shift;
;;
--instance-ip-addr)
ORA_CS_HOSTS="$2"
shift;
;;
--help|-h)
echo -e "\tUsage: `basename $0` "
echo $GETOPT_MANDATORY|sed 's/,/\n/g'|sed 's/:/ <value>/'|sed 's/\(.\+\)/\t --\1/'
echo $GETOPT_OPTIONAL |sed 's/,/\n/g'|sed 's/:/ <value>/'|sed 's/\(.\+\)/\t [ --\1 ]/'
exit 2
;;
--)
shift
break
;;
esac
shift
done
export INSTANCE_SSH_USER
export ORA_CS_HOSTS
export ORA_PROXY_SETUP
export ORA_U01_LUN
export INVENTORY_FILE="$ORA_CS_HOSTS,"
echo -e "Running with parameters from command line or environment variables:\n"
set | egrep '^(ORA_|INVENTORY_|INSTANCE_)' | grep -v '_PARAM='
echo
ANSIBLE_PARAMS="-i ${INVENTORY_FILE} ${ANSIBLE_PARAMS}"
ANSIBLE_EXTRA_PARAMS="${*}"
export ANSIBLE_DISPLAY_SKIPPED_HOSTS=false
ANSIBLE_PLAYBOOK="ansible-playbook"
if ! type ansible-playbook > /dev/null 2>&1; then
echo "Ansible executable not found in path"
exit 3
else
echo "Found Ansible: `type ansible-playbook`"
fi
# exit on any error from the following scripts
set -e
PLAYBOOK="host-provision.yml"
ANSIBLE_COMMAND="${ANSIBLE_PLAYBOOK} ${ANSIBLE_PARAMS} ${ANSIBLE_EXTRA_PARAMS} ${PLAYBOOK}"
echo
echo "Running Ansible playbook: ${ANSIBLE_COMMAND}"
eval ${ANSIBLE_COMMAND}