forked from HolgerHees/smartserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvault.sh
executable file
·52 lines (42 loc) · 1.16 KB
/
vault.sh
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
#!/bin/bash
# Search recursively through the current directory for encrypted values
# - assumes your vault password is in a file vpass
if ! [ -x "$(command -v ansible-vault)" ]; then
echo 'Error: ansible-vault is not installed.' >&2
exit 1
fi
ACTION=""
if [ "$1" != "" ]; then
ACTION="$1"
else
echo "Usage: vault.sh encrypt|decrypt"
exit 1
fi
#echo "${VAULTPW}" > /tmp/mypipe &
#ansible-playbook ... --vault-password-file=$vaultpipe
echo -n "Ansible Password: "
read -s PWD
echo ""
vaultpipe=$(mktemp)
echo "${PWD}" > $vaultpipe &
trap "{ rm -f $vaultpipe; }" TERM KILL QUIT INT HUP EXIT
if [ "${ACTION}" = "encrypt" ]; then
echo -n "Verify Password : "
read -s PWD_check
echo ""
if [ "${PWD}" != "${PWD_check}" ]; then
echo "password not equal"
exit;
fi
grep -rilL ANSIBLE_VAULT ./config/*/vault/ | grep -v demo | while read N
do
echo -n "$N • "
ansible-vault encrypt --vault-password-file $vaultpipe $N
done
elif [ "${ACTION}" = "decrypt" ]; then
grep -ril ANSIBLE_VAULT ./config/*/vault/ | grep -v demo | while read N
do
echo -n "$N • "
ansible-vault decrypt --vault-password-file $vaultpipe $N
done
fi