-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy
executable file
·71 lines (58 loc) · 1.56 KB
/
deploy
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
#!/bin/sh
set -e
cd "$(dirname "${0}")/ansible"
export ANSIBLE_NOCOWS=1
if [ ! -d "venv" ]; then
python3 -m venv venv
venv/bin/python -m pip install ansible-core passlib
fi
if [ -n "$(echo " ${*} " | grep -e ' -h ' -e ' --help ' || :)" ]; then
venv/bin/ansible-playbook --help
exit 0
fi
playbook="${PLAYBOOK-main}"
fqdn="${FQDN-smkent.net}"
env="${ENV-live}"
if [ -z "${fqdn}" ]; then
echo "FQDN is empty" >&2
exit 1
fi
case "${1}" in
hostvars)
exec venv/bin/ansible -i "hosts-${env}.yml" -m debug "${2-all}" \
-e "fqdn=${fqdn}" \
-a 'msg={{hostvars[inventory_hostname]}}'
;;
esac
if [ ! -d "vault/.git" ]; then
if [ -z "${HOMELAB_VAULT}" ]; then
echo "Error: Set \$HOMELAB_VAULT to the URL of your vault repository" >&2
exit 1
fi
git clone "${HOMELAB_VAULT}" vault
fi
if [ "$(cat ".requirements.yml.sha256sum" 2>/dev/null || :)" \
!= "$(sha256sum requirements.yml)" ]; then
(
set -x
venv/bin/ansible-galaxy collection install -r requirements.yml
venv/bin/python -m pip install -r \
"${HOME}/.ansible/collections/ansible_collections/linode/cloud/requirements.txt"
)
sha256sum requirements.yml > ".requirements.yml.sha256sum"
fi
pipe="./fifo"
_rm_pipe() {
if [ -e "${pipe}" ]; then
rm -f "${pipe}"
fi
}
trap _rm_pipe EXIT INT
_rm_pipe
mkfifo "${pipe}"
gpg -d "vault/ansible.asc" > "${pipe}" &
venv/bin/ansible-playbook -i "hosts-${env}.yml" \
-e "@${pipe}" \
-e "fqdn=${fqdn}" \
"${playbook}.yml" \
"${@}"