How to automatically pass vault password when running Ansible playbook


I have an Ansible playbook with vault, and I want to ask for vault password through the prompt box in my web interface and then pass the posted password when running ansible playbook. I tried to use:

echo $password | ansible-playbook test.yml --ask-vault-pass

to pass the password to the playbook, but it doesn't work, the error message is:

"msg": "Attempting to decrypt but no vault secrets found"

I don't want to store password in file for some resons and now I just want to try to automatically pass password to the playbook while running it. Is there any advice to me? The ansible version is 2.4.

Best Solution

You can use a script instead of providing the password through an interactive interface.

Here's an example for your use case:

  1. Save path_to/ file (add permissions to execute) with the following content:

    echo $password
  2. Execute:

    ansible-playbook test.yml --vault-password-file path_to/


  1. Add to ansible.cfg:

  2. Execute:

    ansible-playbook test.yml
Related Question