I'm trying to generate random passwords for set of users, display those password and send them via email.
But after using it in the user module, and later trying to send it as email the password variable creates a new password string.
I want to either append the passwords to the user list.
This is what I have tried so far:
vars:
USER_ID_details:
- user_id: testid1
real_full_name: TESTID_1
groups: wheel
email_id: abc@abc.com
- user_id: randnme
groups: wheel
real_full_name: TESTID_2
email_id: abc@abc.com
id_pass: "{{ lookup('password', '/dev/null length=15 chars=ascii_letters') }}"
- name: create Linux user as per specification
user:
name: "{{ item.user_id }}"
password: "{{ id_pass | password_hash('sha512') }}"
loop: "{{ USER_ID_details }}"
when:
- os_type == "RedHat"
- name: Send the details of the user id and password to the email address
mail:
subject: "*Confidential: {{ item.user_id }} user id created on {{ affected_host }}"
body: "Hello, User id {{ item.user_id }} created on server {{ affected_host }} \n password: {{ id_pass }}"
to: "{{ item.email_id }}"
loop: "{{ USER_ID_details }}"