Commit 57486b26 by James Cammarata

Use the no-user-groups option (-N) for useradd in the user module

If no group was specified, but a group by the same name as the user
exists, an error was raised in the situation where USERGROUPS_ENAB is
enabled in /etc/login.defs (which is the case for almost every major
linux distro). In this case, the user will be put in group 100 (which
is usually the "users" group on those same distros). This is currently
only done in the base class, as the issue may not exist on other
platforms like AIX or the BSDs.

Fixes #6210
parent e798b558
......@@ -289,6 +289,12 @@ class User(object):
self.module.fail_json(msg="Group %s does not exist" % self.group)
cmd.append('-g')
cmd.append(self.group)
elif self.group_exists(self.name):
# use the -N option (no user group) if a group already
# 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.
cmd.append('-N')
if self.groups is not None and len(self.groups):
groups = self.get_groups_set()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment