mirror of https://github.com/ansible/ansible
user: return actual system groups instead of input parameter (#86553)
The user module's 'groups' return value was returning the groups specified in the module input rather than the actual groups the user belongs to on the system. When using append=true, this meant pre-existing groups were missing from the output. Now queries the system for the user's actual group membership after modification, which matches the documented behavior of "List of groups of which the user is a member." Fixes #80669 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>pull/86577/head
parent
7d281b2a7c
commit
52b7d4d092
@ -0,0 +1,3 @@
|
||||
bugfixes:
|
||||
- user - return the actual system groups the user belongs to instead of only the
|
||||
groups specified in the module input (https://github.com/ansible/ansible/issues/80669).
|
||||
@ -0,0 +1,57 @@
|
||||
# Test that the user module returns the actual groups a user belongs to
|
||||
# See: https://github.com/ansible/ansible/issues/80669
|
||||
|
||||
- name: remove test user for groups return test
|
||||
user:
|
||||
name: ansibulluser_groups
|
||||
state: absent
|
||||
|
||||
- name: create test user with initial groups
|
||||
user:
|
||||
name: ansibulluser_groups
|
||||
groups:
|
||||
- daemon
|
||||
- bin
|
||||
state: present
|
||||
register: user_groups_create
|
||||
|
||||
- name: validate groups on initial creation
|
||||
assert:
|
||||
that:
|
||||
- "'bin' in user_groups_create.groups"
|
||||
- "'daemon' in user_groups_create.groups"
|
||||
|
||||
- name: append a group to the test user
|
||||
user:
|
||||
name: ansibulluser_groups
|
||||
groups:
|
||||
- sys
|
||||
append: true
|
||||
state: present
|
||||
register: user_groups_append
|
||||
|
||||
- name: validate groups after append includes all groups
|
||||
assert:
|
||||
that:
|
||||
- "'bin' in user_groups_append.groups"
|
||||
- "'daemon' in user_groups_append.groups"
|
||||
- "'sys' in user_groups_append.groups"
|
||||
|
||||
- name: run user module with no groups param
|
||||
user:
|
||||
name: ansibulluser_groups
|
||||
state: present
|
||||
register: user_groups_noarg
|
||||
|
||||
- name: validate groups returned even when groups param is not set
|
||||
assert:
|
||||
that:
|
||||
- user_groups_noarg.groups is defined
|
||||
- "'bin' in user_groups_noarg.groups"
|
||||
- "'daemon' in user_groups_noarg.groups"
|
||||
- "'sys' in user_groups_noarg.groups"
|
||||
|
||||
- name: clean up test user
|
||||
user:
|
||||
name: ansibulluser_groups
|
||||
state: absent
|
||||
Loading…
Reference in new issue