Verify ansible vault password
# prepare vault password file
printf 'Vault password: ' ; read -se VAULT_PASS ; printf '\n' ;
echo "${VAULT_PASS}" > "${PWFILE}"
# fail out if password is incorrect
! ansible-vault view --vault-password-file "${PWFILE}" "${VAULTFILE}" 1>/dev/null && exit 1
You can use shell to read in the password and save it to a file. Just remember to clean it up at the end! I like to do this right before a shell loop that calls ansible with vaulted values multiple times, so I'm not prompted multiple times to enter the password.
Comments