Encrypting an Existing Inventory File
Let’s assume you have an inventory file with the following content:Running Playbooks with Encrypted Inventory
If you attempt to run a playbook that references an encrypted inventory file without providing the vault password, Ansible will return an error. To execute the playbook successfully, include the--ask-vault-pass option so Ansible can prompt for the vault password, as shown below:
For improved security, avoid running playbooks without providing the vault password. Always use the
--ask-vault-pass option or a secure method to supply the password.Alternative Approach: Storing the Vault Password in a File
An alternative method is to store the vault password in a file and reference it with your command. However, keep in mind that saving the vault password in plain text is not recommended. A more secure approach is to use a Python script (with a.py extension) that dynamically retrieves the vault password—possibly via an API call, a database, or another secure source.
Storing the vault password in plain text poses security risks. Always consider using a dynamic retrieval method to ensure your credentials remain secure.