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
This commit is contained in:
James Cammarata 2014-02-28 11:40:19 -06:00
parent e798b558aa
commit 57486b268a

View file

@ -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()