Using secrets in Ansible playbooks
You have learned the basic usage of secrets in an Ansible playbook in Chapter 3’s Automating notifications section. In this section, we will learn more about their usage and different methods of passing the Vault password.
In the following exercise, we will develop Ansible content to create users in Linux, with their passwords retrieved from an Ansible Vault file:
- Create a
Chapter-13/vars/users.yaml
Ansible Vault file as follows and enter the Vault password:[ansible@ansible Chapter-13]$ ansible-vault create vars/users.yaml
Remember the password, as we need this information when executing the playbook.
- Add content to the variable files as follows:
Figure 13.24 – User details inside an Ansible Vault file
Save the file and exit the editor. The userlist
variable contains details of multiple users and their passwords.
- Verify the file content, as shown in Figure 13.25: