-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunchPlaybook.sh
executable file
·54 lines (45 loc) · 1.19 KB
/
launchPlaybook.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
#!/usr/bin/env bash
set -o errexit # always exit on error
set -o pipefail # honor exit codes when piping
set -o nounset # fail on unset variables
dir=$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)
playbook="personnalServer.yml"
#
# load utilities
#
_utilities="${dir}/utils.sh"
if [ ! -r "${_utilities}" ]; then
echo "Failed to read file ${_utilities}"
exit 1
fi
. "${_utilities}"
usage() {
echo "Usage: $0 [-s <target server>]" 1>&2;
echo "Prerequisite file: ~/.personnalVault must contains the ansible_vault key" 1>&2;
exit 1;
}
targetServer=""
while getopts ":s:" option; do
case "${option}" in
s)
targetServer=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${targetServer}" ] || ! [ -f ~/.personnalVault ]; then
usage
fi
ANSIBLE_FORCE_COLOR=true \
ANSIBLE_HOST_KEY_CHECKING=false \
ANSIBLE_SSH_ARGS="${_ssh_options}" \
ANSIBLE_CONFIG="${dir}/ansible.cfg" \
ansible-playbook -i "${dir}/inventory" \
-l "${targetServer}" --user "${server_user}" \
--private-key="~/.ssh/${server_user}" "${dir}/${playbook}" \
--vault-id=user@~/.personnalVault
checkForError "Setup failed"
displayDuration