configs/ansible_decrypt_string.sh
2025-05-09 23:25:40 +02:00

25 lines
681 B
Bash
Executable file

#!/bin/sh
if [ $# -ge 1 ]; then
v="$1"
shift 1
else
printf "%s\n" "USAGE: $0 inventory_variable [ansible_options]"
printf "%s\n" "EXAMPLES:"
printf "%s\n" "$0 inventory_variable --ask-vault-pass"
printf "%s\n" "$0 inventory_variable --vault-id other/ansible-vault/default@pass-client.sh"
exit 1;
fi;
filelist=$(grep -r "${v}:" | grep -v "#.*${v}" | cut -d':' -f 1 | tr '\n' ' ')
#printf "%s\n" "filelist: $filelist" 1>&2
if [ "$filelist" = "" ]; then
printf "%s\n" "ERROR: No file found containing variable: ${v}" 1>&2
exit 2;
fi;
for f in $filelist ; do
printf "%s\n" "$f"
ansible localhost -m debug -a var=${v} -e @${f} $@ ;
done;