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.
More on Vault, Privilege Escalation and Error Handling
What is Ansible Vault?BeginnerWhich `ansible-vault` commands do you use day to day?BeginnerHow do you supply the vault password when running a playbook?BeginnerWhat is `encrypt_string` and when is it better than encrypting a whole file?IntermediateWhat are vault IDs and why use them?AdvancedHow is Vault data encrypted and what does the file look like?Advanced