a way to automatically pass vault password when running ansible playbook

Hi,

What i am trying to do :

ansible-playbook -i playbooks/hosts/vt-hosts playbooks/vault-test.yml --ask-vault-pass

I have some properties encrypted using vault. The idea i want to code is to combine using some CI tool like Team City asking for vault password and then running ancible playbook to setup hosts. Everything works fine except i would like to find a way to pass captured password from my CI as a parameter to ancible playbook executionn.

Let’s assume i would have my password in variablie VP. Is there any way to automatically pass password from VP to
ansible-playbook -i playbooks/hosts/vt-hosts playbooks/vault-test.yml --ask-vault-pass (in bash)

when the promp would appear:
Vault password:

Smth like
echo $VP | ansible-playbook -i playbooks/hosts/vt-hosts playbooks/vault-test.yml --ask-vault-pass
does not work.

I dont like to store password in file as a plain text and pass it to ansible-playbook because when some errors would occur the file with password could be not delete from the environments.

Please help is automatically passing password to that prompt is possible.

Michal Klasinski

Trying to have some script enter stuff that is prompted towards the user usually ends up in a very messy result. I would advice against going down that road.

While I haven’t tested this I would suggest “vaulting” your var file using a script as described in
https://docs.ansible.com/ansible/playbooks_vault.html#running-a-playbook-with-vault
and use the script to get and pass your vault password however you want to.