forked from OpenConext/OpenConext-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovision
executable file
·79 lines (68 loc) · 1.6 KB
/
provision
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
#!/bin/bash
set -e
# helper function: check if a specified value is present in a space-separted list
listcontains() {
match=$1
shift
for word in $@
do
[[ $word = $match ]] && return 0
done
return 1
}
# check ansible
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, found $ANSVER instead."
exit 1
fi
# parse parameters
help="Usage: $0 vm [ANSIBLE_OPT]\n $0 <ENV> <SSH_USERNAME> <SECRET_FILE> [ANSIBLE_OPT]"
if [ "$#" -eq 0 ]
then
echo -e "$help"
exit 1
fi
env=$1
shift
if [ "$env" = "vm" ]
then
user="vagrant"
secret="secrets/vm.yml"
elif [ $# -lt 3 ]
then
echo -e "$help"
exit 1
else
# check environment
known_envs='vm test acc prod diy-test diy'
if ! listcontains "$env" ${known_envs}
then
echo "The environment '$env' is unknown ";
exit 1
fi
user=$1
secret=$2
shift; shift
fi
# find matching playbook
playbook="provision.yml"
listcontains "$env" "vm" && playbook="provision-vm.yml"
listcontains "$env" "diy diy-test" && playbook="provision-diy.yml"
# find inventory
inventory="inventory/$env"
if ! [ -e $inventory ]
then
echo "Inventory file '$inventory' for environment '$env' not found."
exit 1
fi
# run vm
if [ "$env" = "vm" ]
then
vagrant up
fi
# run ansible
echo "executing: ansible-playbook -i \"$inventory\" -u \"$user\" -K \"$playbook\" --extra-vars=\"secrets_file=$secret\" $@"
exec ansible-playbook -i "$inventory" -u "$user" -K "$playbook" --extra-vars="secrets_file=$secret" $@