-
Notifications
You must be signed in to change notification settings - Fork 0
/
votsible.sh
executable file
·121 lines (103 loc) · 3.01 KB
/
votsible.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
112
113
114
115
116
117
118
119
120
#!/bin/bash
set -e
cd "$(cd "$(dirname "$0")"; pwd)"
help_and_exit () {
fatal <<-__HELP_MSG
Usage:
$0 [ -t sometag ] [ ... ]
__HELP_MSG
exit
}
die () {
echo $* >&2
exit 1
}
ensure_ansible () {
if ! test -f ansible-deps-cache/.versions 2>/dev/null; then
curl https://raw.githubusercontent.com/epfl-si/ansible.suitcase/master/install.sh | \
SUITCASE_DIR=$PWD/ansible-deps-cache \
SUITCASE_ANSIBLE_VERSION=9.3.0 \
bash -x
fi
export PATH="$PWD/ansible-deps-cache/bin:$PATH"
export ANSIBLE_ROLES_PATH="$PWD/ansible-deps-cache/roles"
export ANSIBLE_COLLECTIONS_PATH="$PWD/ansible-deps-cache"
. ansible-deps-cache/lib.sh
}
# ------------------------------------------------------------------------------
### defaults
mode=ansible-playbook
playbook_flags="-e @vars/global_vars.yml"
ansible_flags="-e @vars/global_vars.yml"
inventory_mode="test"
keybase_path="/keybase/team/epfl_evoting"
dela_version="0.4.4"
declare -a ansible_args
while [ "$#" -gt 0 ]; do
case "$1" in
--help) help_and_exit ;;
-m) mode=ansible
ansible_args+=("-m")
shift
;;
--prod)
inventory_mode="prod"
dela_version="0.4.5-alpha"
shift
;;
--qual)
inventory_mode="qual"
shift
;;
--test)
inventory_mode="test"
shift
;;
--demo)
inventory_mode="demo"
shift
;;
--dev|--local)
inventory_mode="dev"
shift
;;
-g|--galaxy) mode=galaxy
shift
;;
-k) keybase_path=$2
shift 2
;;
*)
ansible_args+=("$1")
shift ;;
esac
done
### validation
inventory="inventories/hosts-${inventory_mode}.yml"
[ -f "$inventory" ] || die "Inventory file $inventory does not exist"
[ -d "$keybase_path" ] || die "Invalid keybase path $keybase_path. May be keybase is not running ?"
if [ -f "playbook-${inventory_mode}.yml" ] ; then
playbook="playbook-${inventory_mode}.yml"
else
playbook="playbook.yml"
fi
### execution
ensure_ansible
dela_version_underscore=${dela_version//./_}
case "$mode" in
ansible-playbook)
ansible-playbook $playbook_flags -i $inventory \
"${ansible_args[@]}" \
-e "inventory_mode=$inventory_mode" \
-e "keybase_path='$keybase_path'" \
-e "dela_version='$dela_version'" \
-e "dela_version_underscore='$dela_version_underscore'" \
$playbook
;;
ansible)
ansible -i $inventory $ansible_flags "${ansible_args[@]}"
;;
galaxy)
ansible-galaxy "${ansible_args[@]}"
;;
esac