Per http://docs.ansible.com/ansible/playbooks_vault.html you can set an environment variable to use a password file for vault access. We can use this to create an environment variable to hold the password.
Copy vault-env from this project to ~/bin. Then add this to your ~/.bashrc:
export ANSIBLE_VAULT_PASSWORD_FILE=~/bin/vault-envNow just export your password in your shell as needed. Don't be a douche and put this in your profile though.
export ANSIBLE_VAULT_PASSWORD=<password>
Quite correct. I failed to make the file executable when I started working with vault passwords. The documentation can be misleading in that it does not clarify how password files work in all references. So, depending on where you come into the docs, there can be some misunderstanding.
For example, in "Storing passwords in files" the
--vault-password-fileoption ofansible-playbookis described as identifying the file the password is stored in. There is nothing about executable permissions.The docs for the ANSIBLE_VAULT_PASSWORD_FILE environment variable say "If executable, it will be run and the resulting stdout will be used as the password." It does not say the file contents will otherwise be used.
I have found, only in "Setting a default password source" is it clearly stated that the file "can be either a file containing the password (in plain text), or it can be a script (with executable permissions set) that returns the password."
This applies to ALL password file references. The
--vault-idand--vault-password-fileoptions,DEFAULT_VALUE_IDENTITY_LIST,DEFAULT_VAULT_PASSWORD_FILEandANSIBLE_VAULT_PASSWORD_FILEenvironment variables, and thevault_identity_listconfiguration option all identify files as the password source. If the file is executable, the password is the output of the executed script. If not, the password is the file content.