From 57486b268abd6ddc6898cc899e0355a0c17cf55c Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Fri, 28 Feb 2014 11:40:19 -0600 Subject: [PATCH] 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 --- library/system/user | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/library/system/user b/library/system/user index 928044a79d..a6d3a0ec32 100644 --- a/library/system/user +++ b/library/system/user @@ -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()