Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ansible/ansible.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris James <etcet@users.noreply.github.com>2022-06-17 20:16:42 +0300
committerMatt Martz <matt@sivel.net>2022-09-27 20:47:58 +0300
commitfa250b379639075239064f76df99b29e4090c14f (patch)
tree923a8ad907c8e92348b76be00130376d23145201
parentfa0655228a818134082b5fcb2dfcf6f94a0f4299 (diff)
user - Use -n instead of -N for luseradd on all distros (#75042)backport-ea351f0-stable-2.13
* Use -n instead of -N for luseradd on all distros Co-authored-by: Chris James <git@etcet.net> (cherry picked from commit ea351f0ae2bca23cdd7c24547a6607a50186a116)
-rw-r--r--changelogs/fragments/75042-lowercase-dash-n-with-luseradd-on-all-distros.yml2
-rw-r--r--lib/ansible/modules/user.py32
-rw-r--r--test/integration/targets/user/tasks/test_local.yml2
3 files changed, 22 insertions, 14 deletions
diff --git a/changelogs/fragments/75042-lowercase-dash-n-with-luseradd-on-all-distros.yml b/changelogs/fragments/75042-lowercase-dash-n-with-luseradd-on-all-distros.yml
new file mode 100644
index 00000000000..f64b07dcf3e
--- /dev/null
+++ b/changelogs/fragments/75042-lowercase-dash-n-with-luseradd-on-all-distros.yml
@@ -0,0 +1,2 @@
+bugfixes:
+ - user - fix creating a local user if the user group already exists (https://github.com/ansible/ansible/pull/75042)
diff --git a/lib/ansible/modules/user.py b/lib/ansible/modules/user.py
index 3e35e90facd..a94cc816561 100644
--- a/lib/ansible/modules/user.py
+++ b/lib/ansible/modules/user.py
@@ -664,22 +664,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()
diff --git a/test/integration/targets/user/tasks/test_local.yml b/test/integration/targets/user/tasks/test_local.yml
index 16c79c57812..f18a5ea49ea 100644
--- a/test/integration/targets/user/tasks/test_local.yml
+++ b/test/integration/targets/user/tasks/test_local.yml
@@ -85,6 +85,7 @@
- testgroup2
- testgroup3
- testgroup4
+ - local_ansibulluser
tags:
- user_test_local_mode
@@ -139,6 +140,7 @@
- testgroup2
- testgroup3
- testgroup4
+ - local_ansibulluser
tags:
- user_test_local_mode