Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions roles/users_add/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# Suppress ansible-lint var-naming warning for third-party role variables
# noqa: var-naming[no-role-prefix]
# Only force a password change on accounts that were just created. update_password:
# on_create means existing users' password hashes are never rewritten, so we must not
# reset their password-aging either (that would prompt them to change their password at
# next login). Filtering on .changed restricts chage -d 0 to newly-created accounts.
- name: Force password change on first login

Check warning on line 7 in roles/users_add/handlers/main.yml

View workflow job for this annotation

GitHub Actions / build

var-naming[no-role-prefix]

Variables names from within roles should use users_add_ as a prefix. (register: chage_output)

Check warning on line 7 in roles/users_add/handlers/main.yml

View workflow job for this annotation

GitHub Actions / build

var-naming[no-role-prefix]

Variables names from within roles should use users_add_ as a prefix. (register: chage_output)
ansible.builtin.command: "chage -d 0 {{ item.username }}"
loop: "{{ users_add_userlist | default([]) }}"
ansible.builtin.command: "chage -d 0 {{ item.name }}"
loop: "{{ users_add_created.results | default([]) | selectattr('changed') | list }}"
loop_control:
label: "{{ item.name }}"
register: chage_output # This will register the output of the command to a variable
changed_when: "'Password aging updated' in chage_output.stdout"
1 change: 1 addition & 0 deletions roles/users_add/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# Initial password required for sudo - must be changed on first login
update_password: on_create # This ensures the password is only set when the user is created
loop: "{{ users_add_userlist | default([]) }}"
register: users_add_created # Per-user result; handler uses .changed to chage only new accounts
notify:
- Force password change on first login
no_log: true # Prevent password hashes from being logged
Expand Down
Loading