# a way to automatically pass vault password when running ansible playbook

**URL:** <https://forum.ansible.com/t/a-way-to-automatically-pass-vault-password-when-running-ansible-playbook/19810>\
**Category:** Ansible Project\
**Created:** [November 19, 2015, 3:20pm UTC](https://forum.ansible.com/t/a-way-to-automatically-pass-vault-password-when-running-ansible-playbook/19810 "2015-11-19T15:20:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michal\_Klasinski](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@Michal\_Klasinski](https://forum.ansible.com/u/Michal_Klasinski)\
**Post date:** [November 19, 2015, 3:20pm UTC](https://forum.ansible.com/t/a-way-to-automatically-pass-vault-password-when-running-ansible-playbook/19810/1 "2015-11-19T15:20:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Markus\_Ellers](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Markus\_Ellers](https://forum.ansible.com/u/Markus_Ellers)\
**Post date:** [November 21, 2015, 8:41pm UTC](https://forum.ansible.com/t/a-way-to-automatically-pass-vault-password-when-running-ansible-playbook/19810/2 "2015-11-21T20:41:55Z")

</div>

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](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.
