user - Use -n instead of -N for luseradd on all distros (#75042)

* Use -n instead of -N for luseradd on all distros

Co-authored-by: Chris James <git@etcet.net>
pull/78087/head
Chris James 2 years ago committed by GitHub
parent 44b5314174
commit ea351f0ae2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- user - fix creating a local user if the user group already exists (https://github.com/ansible/ansible/pull/75042)

@ -693,22 +693,26 @@ class User(object):
# exists with the same name as the user to prevent
# errors from useradd trying to create a group when
# USERGROUPS_ENAB is set in /etc/login.defs.
if os.path.exists('/etc/redhat-release'):
dist = distro.version()
major_release = int(dist.split('.')[0])
if major_release <= 5 or self.local:
cmd.append('-n')
if self.local:
# luseradd uses -n instead of -N
cmd.append('-n')
else:
if os.path.exists('/etc/redhat-release'):
dist = distro.version()
major_release = int(dist.split('.')[0])
if major_release <= 5:
cmd.append('-n')
else:
cmd.append('-N')
elif os.path.exists('/etc/SuSE-release'):
# -N did not exist in useradd before SLE 11 and did not
# automatically create a group
dist = distro.version()
major_release = int(dist.split('.')[0])
if major_release >= 12:
cmd.append('-N')
else:
cmd.append('-N')
elif os.path.exists('/etc/SuSE-release'):
# -N did not exist in useradd before SLE 11 and did not
# automatically create a group
dist = distro.version()
major_release = int(dist.split('.')[0])
if major_release >= 12:
cmd.append('-N')
else:
cmd.append('-N')
if self.groups is not None and len(self.groups):
groups = self.get_groups_set()

@ -86,6 +86,7 @@
- testgroup3
- testgroup4
- testgroup5
- local_ansibulluser
tags:
- user_test_local_mode
@ -163,6 +164,7 @@
- testgroup3
- testgroup4
- testgroup5
- local_ansibulluser
tags:
- user_test_local_mode

Loading…
Cancel
Save