initial commit

This commit is contained in:
2023-07-04 17:43:07 +02:00
commit e8f68529cb
2 changed files with 103 additions and 0 deletions

30
ansible-vault-tools.sh Executable file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2023 Max Mehl <https://mehl.mx>
#
# SPDX-License-Identifier: Apache-2.0
CMD=$1
# Encrypt
if [[ $CMD == "encrypt" ]]; then
pass=$2
vaultpw=$(echo -n "$pass" | ansible-vault encrypt_string 2> /dev/null)
# Decrypt
elif [[ $CMD == "decrypt" ]]; then
host=$2
var=$3
# run ansible msg for variable
# send return as JSON
vaultpw=$(ANSIBLE_LOAD_CALLBACK_PLUGINS=1 ANSIBLE_STDOUT_CALLBACK=json ansible "$host" -m debug -a "msg={{$var}}" 2> /dev/null)
# Parse JSON to just get the "msg"
vaultpw=$(jq -r ".plays[].tasks[].hosts[].msg" <<< "$vaultpw")
else
echo "Invalid command"
exit 1
fi
echo "$vaultpw"