Newbie to ansible…
Use case: at the create time users are assigned a default password and will be asked to change the password at the first login
What I came up with (in a role)…
-
name: Create User
user: name=“{{ item.username }}”
groups=“{{ def_user_groups | union(item.groups) | join(‘,’) if item.groups is defined
and item.groups is iterable
else def_user_groups | join(”,“) }}”
comment=“{{ item.name }}”
uid=“{{ item.uid }}”
password=“{{ def_user_passwd }}”
update_password=on_create
append=yes
state=present
with_items:
add_users
tags: ‘users’ -
name: List users who has default password
shell: grep “{{ def_user_passwd }}” /etc/shadow | cut -d’:’ -f1
register: users_with_def_passwd -
name: Force user with default password to change password at next login
command: chage -d 0 {{ item }}
with_items: users_with_def_passwd.stdout.split()
Is there a better way to accomplish this? Feel like I should be able to somehow distinguish the newly created users and be able to do this more elegantly…
Thought I run it by the experts.
Appreciate your feedback.
Thanks
.raja