I want to use Ansible te create user on my OS upon initialization of the instance. To do so I have a playbook in which I defined a role. In this role I have the following:
name: add users to local system
user:
name: "{{ item.username }}"
password: "{{ item.password }}"
uid: "{{ item.uid }}"
group: "{{ item.group }}"
with_items: "{{ Ansible_Vault_SecretsFile }}"
This way I can specify the details of the users (username, password, uid and group) in the different secrets files I have for different environments. The password in the secrets file is in plain text. Since it is written to /etc/shadow it needs to be hashed. Is there a way to automatically hash the password variable in this role?
Edit: To clarify further, I know the secrets file is encrypted, but when the contents in this case usernames and passwords are decrypted before they are stored in the /etc/shadow file.
My secrets file looks like this:
Ansible_Vault_SecretsFile:
username: user1
password: MyPassword
uid: 100
group: users
username: user2
password: MyPassword2
uid: 101
group: users
the role iterates through the secrets file and in this case creates two users. In the /etc/shadow file the passwords are stored as MyPassword and Mypassword2, but in order to log in those plaintext passwords need to be hashed. I'm looking for a way to do this automatically.