To set and use a password for Ansible Vault in a playbook, follow these steps:
Create a file with the secret data that you want to encrypt, for example secrets.txt
.
Use the ansible-vault create
command to create an encrypted version of the file, and set a password for it:
ansible-vault create secrets.txt
Follow the prompts to enter and confirm the password for the encrypted file.
Edit the Ansible playbook to reference the encrypted file. For example:
- name: Set secret data set_fact: secret_data: "{{ lookup('file', 'secrets.txt') }}"
--ask-vault-pass
option:ansible-playbook playbook.yml --ask-vault-pass
You will be prompted to enter the password for the encrypted file.
Alternatively, you can use the --vault-password-file
option to specify a file containing the password:
ansible-playbook playbook.yml --vault-password-file /path/to/password.txt