-
Notifications
You must be signed in to change notification settings - Fork 2
/
go.sh
executable file
·107 lines (95 loc) · 2.46 KB
/
go.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
#!/bin/bash
source ./.ansible-sys/scripts/setup.sh
#######################################################################
# Functions
usage () {
PRG=$(basename $0)
echo "$PRG -p PLAYBOOK -u USER [-l LIMIT] [-t TAGS] [-z SKIP] [-v VERBOSITY] [-k KEY] [-e EXTRAVARS] [-s] [-c] [-h]"
echo " -p PLAYBOOK path to playbook"
echo " -u USER user profile to load"
echo " -l LIMIT limit to host"
echo " -t TAGS run only tasks with provided tags"
echo " -z SKIP skips tasks with provided tags"
echo " -v VERBOSITY v, vv, vvv, vvvv"
echo " -k KEY use private key"
echo " -e EXTRAVARS include as extra vars"
echo " -s run as sudo"
echo " -c run in check mode"
echo " -h show help"
exit 0
}
get_playbook () {
playbook="playbooks/${1}.yml"
echo $playbook
}
#######################################################################
# Get Input
while getopts ":p:u:l:t:z:v:e:k:sch" arg; do
case $arg in
p)
playbook=$(get_playbook "${OPTARG}")
;;
u)
user="${OPTARG}"
uservars=" --extra-vars \"@user_profiles/${user}.yml\""
;;
l)
limit=" --limit \"${OPTARG}\""
;;
t)
tags=" --tags \"${OPTARG}\""
;;
z)
skip=" --skip-tags \"${OPTARG}\""
;;
v)
verbosity=" -${OPTARG}"
;;
k)
key=" --private-key \"${OPTARG}\""
;;
e)
extravars=" --extra-vars \"${OPTARG}\""
;;
s)
sudo=" --ask-become-pass"
;;
c)
check=" --check"
;;
h)
usage
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# Check mandatory fields
mandatory_fields=( "playbook" "user" )
mandatory_fields_set=true
for arg in ${mandatory_fields[@]}; do
if [ -z "${!arg}" ]; then
echo "Missing argument: ${arg^^}"
mandatory_fields_set=false
fi
done
if [ ${mandatory_fields_set} = false ]; then
usage
exit 1
fi
# Check playbook exists
if [ ! -f ${playbook} ]; then
echo "'${playbook}' does not exist"
exit 1
fi
#######################################################################
exe="ansible-playbook ${playbook} --diff${limit}${tags}${skip}${verbosity}${sudo}${check}${key}${uservars}${extravars}"
echo "${exe}"
eval "${exe}"
rm "$(find . -type f -name "*.retry")" 2> /dev/null