forked from OpenConext/OpenConext-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansible-env
executable file
·36 lines (31 loc) · 1001 Bytes
/
ansible-env
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
#!/bin/bash
# USAGE: ./ansible-env [env-name] [playbook-file] [remote username]
set -e
listcontains() {
match=shift
for word in $@
do
[[ $word = $match ]] && return 0
done
return 1
}
known_envs='vm test acc prod diy-test diy'
if listcontains "$1" ${known_envs}
then
echo "The environment '$1' is not a valid environment";
exit 1
fi
ANSVER=$(ansible --version|head -1|cut -d " " -f 2)
ANSVER1=$(echo "$ANSVER" | cut -d '.' -f 1)
ANSVER2=$(echo "$ANSVER" | cut -d '.' -f 2)
if [ "$ANSVER1" -le 1 -a "$ANSVER2" -lt 9 ]; then
echo "Requires at least Ansible 1.9"
exit 1
fi
if [ "$1" == 'vm' ]; then
# no need to provide the username when targeting vagrant: it's always the same.
ansible-playbook -i inventory/vm -u vagrant "$2" "${@:5}" --extra-vars="secrets_file=secrets/vm.yml"
else
echo "executing ansible-playbook -i inventory/$1 -u $3 -K $2 ${@:5} --extra-vars=secrets_file=$4"
ansible-playbook -i "inventory/$1" -u "$3" -K "$2" "${@:5}" --extra-vars="secrets_file=$4"
fi