-
Notifications
You must be signed in to change notification settings - Fork 9
/
init-ansible
executable file
·56 lines (42 loc) · 1.22 KB
/
init-ansible
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
#!/usr/bin/env bash
#
# This program installs the published ansible roles required by the playbooks.
#
# Usage:
# init-ansible
set -o errexit -o nounset -o pipefail
ExecName=$(readlink --canonicalize "$0")
readonly ExecName
PlaybooksDir=$(dirname "$ExecName")
readonly PlaybooksDir
main()
{
ansible-galaxy install --force -r "$PlaybooksDir"/requirements-ansible.yml
local roleDir
while read -r roleDir; do
local reqFile="$roleDir"/requirements.yml
if [[ -f "$reqFile" ]]; then
# ansible-galaxy won't update roles installed through dependencies, so
# delete all roles before updating
local roles
readarray -t roles < <(listSubDirs "$roleDir")
local role
for role in "${roles[@]}"; do
if [[ -f "$roleDir"/"$role"/meta/.galaxy_install_info ]]; then
ansible-galaxy role remove --roles-path="$roleDir" "$role"
fi
done
ansible-galaxy role install --role-file="$reqFile" --roles-path="$roleDir"
fi
done < <(find "$PlaybooksDir" -type d -name roles)
}
listSubDirs()
{
local roleDir="$1"
if [[ "$OSTYPE" == "darwin"* ]]; then
find "$roleDir" -maxdepth 1 -mindepth 1 -type d -print0 | xargs -0 stat -f '%f\n'
else
find "$roleDir" -maxdepth 1 -mindepth 1 -type d -printf '%f\n'
fi
}
main