forked from OpenConext/OpenConext-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovision
executable file
·99 lines (85 loc) · 2.58 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
set -e
export ANSIBLE_ROLES_PATH="roles:roles-external"
# helper function: check if a specified value is present in a space-separated list
listcontains() {
match=$1
shift
for word in $@
do
[[ $word = $match ]] && return 0
done
return 1
}
# 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" ] || [ $env = "devvm" ]
then
user="vagrant"
secret="environments/vm/secrets/vm.yml"
environment_dir="environments/vm/"
elif [ $# -lt 2 ]
then
echo -e "$help"
exit 1
else
user=$1
secret=$2
environment_dir="environments-external/$env/"
shift; shift
fi
# Download extra roles when requirements.yml is present
if [ -f "$environment_dir"/requirements.yml ]
then
echo "Downloading roles to roles-external"
ansible-galaxy install -r "$environment_dir"/requirements.yml -f -p .
else
echo "No extra roles found to be downloaded"
fi
# find matching playbook
playbook="provision.yml"
#listcontains "$env" "vm" && playbook="provision-vm.yml"
# find inventory
if [ $env = "vm" ] || [ $env = "template" ]
then
inventory="environments/$env/inventory"
elif [ $env = "devvm" ]
then
inventory="environments/vm/inventory"
else
inventory="environments-external/$env/inventory"
fi
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
if [ "$env" = "devvm" ]
then
ENV=dev vagrant up
fi
# run ansible
if [ $env = "vm" ] || [ $env = "template" ]
then
echo "executing: ansible-playbook -i \"$inventory\" -u \"$user\" \"$playbook\" --extra-vars=\"secrets_file=$secret environment_dir=$environment_dir\" $@"
ansible-playbook -i "$inventory" -u "$user" "$playbook" --extra-vars="secrets_file=$secret" -e environment_dir="$environment_dir" $@
elif [ $env = "devvm" ]
then
echo "executing: ansible-playbook -i \"$inventory\" -u \"$user\" \"$playbook\" --extra-vars=\"secrets_file=$secret environment_dir=\$environment_dir @environments/vm/group_vars/dev.yml\" $@"
ansible-playbook -i "$inventory" -u "$user" "$playbook" --extra-vars="secrets_file=$secret" -e environment_dir="$environment_dir" -e "@environments/vm/group_vars/dev.yml" $@
else
echo "executing: ansible-playbook -i \"$inventory\" -u \"$user\" \"$playbook\" --extra-vars=\"secrets_file=$secret\" environment_dir=\"$environment_dir\" $@"
ansible-playbook -i "$inventory" -u "$user" "$playbook" --extra-vars=secrets_file="$secret" -e environment_dir="$environment_dir" $@
fi