-
Notifications
You must be signed in to change notification settings - Fork 0
/
generico.sh
executable file
·77 lines (56 loc) · 1.49 KB
/
generico.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
#!/usr/bin/env bash
function usage() {
SCRIPT=$(basename $0)
printf "usage: ${SCRIPT} <playbook> <inventory_directory> (--help | [-t <tag_1><,tag_2>...] [options])\n\n" >&2
printf "*************************************************\n"
printf "ansible-playbook --help\n"
ansible-playbook --help
printf "*************************************************\n"
}
function valid_playbooks() {
echo "Valid playbooks are:"
for playbook_file in $(ls *.yml)
do
playbook_file="${playbook_file%%.*}"
echo -e "\t- ${playbook_file#*/}"
done
}
if [[ ${#} -lt 2 ]]; then
echo "At least two parameters are needed:"
usage
valid_playbooks
exit 1
fi
if [[ ! -f ${1}.yml ]]; then
echo "Playbook ${1} (real file location ${1}.yml) doesn't exists"
usage
valid_playbooks
exit 2
fi
PLAYBOOK="${1}.yml"
shift
if [[ ! -d ${1} ]]; then
echo "${1} is not a directory. Please provide a valid inventory directory."
usage
exit 3
fi
INVENTORY_DIRECTORY="${1}"
shift
if [[ ! -z ${1} ]]; then
if [ "${1}" == "--help" ]; then
usage
valid_playbooks
exit 0
else
if ! [[ "${1}" =~ -.* ]]; then
TAGS="-t ${@}"
else
TAGS="${@}"
fi
fi
fi
export ANSIBLE_HOST_KEY_CHECKING=False
#CMD="ansible-playbook -v ${PLAYBOOK} -i ${INVENTORY_DIRECTORY} --module-path=roles --vault-password-file .vault_pass.txt ${TAGS}"
CMD="ansible-playbook -v ${PLAYBOOK} -i ${INVENTORY_DIRECTORY} --module-path=roles ${TAGS}"
echo "Executing ${CMD}"
${CMD}