-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvault
executable file
·47 lines (40 loc) · 1.1 KB
/
vault
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
#!/bin/bash -e
# if no arguments then return the vault secret
# else encrypt a new secret
if [[ $# -eq 0 ]]; then
if [[ ! -f vault.asc ]]; then
echo >&2 "error: unable to find vault.asc!"
exit 1
fi
gpg --batch --quiet --decrypt vault.asc
exit 0
fi
if [[ $1 == -w ]]; then
VAULT_ID=w@./wvault
shift
else
VAULT_ID=p@./vault
fi
if [[ $1 == -v || $1 == --view ]]; then
if [[ $# -eq 2 && -f $2 ]]; then
ansible-vault view --vault-id ${VAULT_ID} "$2"
elif [[ $# -eq 3 && -f $2 ]]; then
if ! command -v yq > /dev/null 2>&1; then
echo >&2 "missing 'yq' (https://github.com/mikefarah/yq)"
exit 1
fi
yq e ".${3}" "$2" |
ansible-vault decrypt --vault-id ${VAULT_ID} - 2> /dev/null
else
echo >&2 "usage: $(basename "$0") [-w] -v ./to/file OR ./roles/file.yml var"
fi
else
if [[ $# -eq 1 && -f $1 ]]; then
ansible-vault encrypt --vault-id ${VAULT_ID} "$1"
elif [[ $# -eq 2 ]]; then
ansible-vault encrypt_string --vault-id ${VAULT_ID} --name "$1" "$2"
else
echo >&2 "usage: $(basename "$0") [-w] [-v|--view] ./to/file OR key value"
fi
fi
exit 0