Interview Prep/Ansible/Vault, Privilege Escalation and Error Handling

How can the vault password be provided by a script, and why would you do it?

IntermediateConceptVault, Privilege Escalation and Error Handling
Answer

If the file passed to --vault-password-file is executable, Ansible runs it and uses its stdout as the password. The script can fetch the secret from AWS Secrets Manager, HashiCorp Vault or the OS keychain, so it never sits in a file on disk.

#!/usr/bin/env bash
# vault-pass.sh  (chmod +x)
aws secretsmanager get-secret-value --secret-id ansible/vault \
  --query SecretString --output text
ansible-playbook site.yml --vault-password-file ./vault-pass.sh

Scripts for --vault-id follow the same rule and are given the vault ID as --vault-id argument when the file name ends in -client.

All Ansible questions Roadmap: Ansible

More on Vault, Privilege Escalation and Error Handling