0

I need to run a Playbook with Inventory file, which is password protected. I know that we can give password by prompt (when running the playbook) or using secret file which have the password of inventory.

My question is "is there a way to specify inventory file's password within the playbook"

1 Answers1

0

The vault password can be exported to the machine where you want to run the ansible playbook (like a local machine or Jenkins, etc.) and run the playbook as follows:

To export the ansible vault password

export VAULT_PASSWORD=valut-password-here

Then you can use it in two ways, either directly.

ansible-playbook your-playbook.yml --vault-password-file <(cat <<<"$VAULT_PASSWORD")

By using the Python OS module, you can read from the environment and then pass it to the Ansible Playbook.

ansible-playbook your-playbook.yml --vault-password-file ./vault_password.py

where vault_password.py has this code:

#!/usr/bin/env python
import os
print os.environ['VAULT_PASSWORD']
Arbab Nazar
  • 22,378
  • 10
  • 76
  • 82