How to set and use sudo password for Ansible Vault

How to set and use sudo password for Ansible Vault

To set and use a password for Ansible Vault in a playbook, follow these steps:

  1. Create a file with the secret data that you want to encrypt, for example secrets.txt.

  2. Use the ansible-vault create command to create an encrypted version of the file, and set a password for it:

refer ‮al:ot‬utturi.com
ansible-vault create secrets.txt
  1. Follow the prompts to enter and confirm the password for the encrypted file.

  2. Edit the Ansible playbook to reference the encrypted file. For example:

- name: Set secret data
  set_fact:
    secret_data: "{{ lookup('file', 'secrets.txt') }}"
  1. To use the password when running the playbook, use the --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
Created Time:2017-10-29 22:08:37  Author:lautturi