Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 776
snow Avatar asked Jan 30 '18 04:01

snow


1 Answers

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/vault_secret.sh file (add permissions to execute) with the following content:

    #!/bin/bash
    echo $password
    
  2. Execute:

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

Alternatively:

  1. Add to ansible.cfg:

    [defaults]
    vault_password_file=path_to/vault_secret.sh
    
  2. Execute:

    ansible-playbook test.yml
    
like image 171
techraf Avatar answered Sep 20 '22 01:09

techraf