Fix lusermod using a group name and not id (#61965) (#77914)

* Fix lusermod using a group name and not id (#61965)
This commit is contained in:
Julien Lecomte 2022-05-31 19:07:06 +02:00 committed by GitHub
parent 9f7956ba30
commit 33beeace10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

View File

@ -0,0 +1,2 @@
bugfixes:
- prevent lusermod from using group name instead of group id (https://github.com/ansible/ansible/pull/77914)

View File

@ -821,7 +821,7 @@ class User(object):
ginfo = self.group_info(self.group)
if info[3] != ginfo[2]:
cmd.append('-g')
cmd.append(self.group)
cmd.append(ginfo[2])
if self.groups is not None:
# get a list of all groups for the user, including the primary

View File

@ -85,6 +85,7 @@
- testgroup2
- testgroup3
- testgroup4
- testgroup5
tags:
- user_test_local_mode
@ -121,6 +122,28 @@
tags:
- user_test_local_mode
- name: Assign named group for local_ansibulluser
user:
name: local_ansibulluser
state: present
local: yes
group: testgroup5
register: local_user_test_6
tags:
- user_test_local_mode
# If we don't re-assign, then "Set user expiration" will
# fail.
- name: Re-assign named group for local_ansibulluser
user:
name: local_ansibulluser
state: present
local: yes
group: local_ansibulluser
ignore_errors: yes
tags:
- user_test_local_mode
- name: Remove local_ansibulluser again
user:
name: local_ansibulluser
@ -139,6 +162,7 @@
- testgroup2
- testgroup3
- testgroup4
- testgroup5
tags:
- user_test_local_mode
@ -149,6 +173,7 @@
- local_user_test_2 is not changed
- local_user_test_3 is changed
- local_user_test_4 is changed
- local_user_test_6 is changed
- local_user_test_remove_1 is changed
- local_user_test_remove_2 is not changed
tags: