From 638191cd07ba1afe5ea61ff5268351ab77541139 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 30 Mar 2016 20:16:46 -0400 Subject: fix adding of users without a group revision 1179 regressed adding a user that did not have a 'groups' entry present. This should handle that correctly, making 'add_user' able to take: a.) groups="group1,group2" b.) groups=["group1", "group2"] c.) groups=None d.) no groups parameter LP: #1562918 --- cloudinit/distros/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index 418421b9..5563ae43 100644 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -362,15 +362,18 @@ class Distro(object): redact_opts = ['passwd'] + # support kwargs having groups=[list] or groups="g1,g2" groups = kwargs.get('groups') if groups: if isinstance(groups, (list, tuple)): + # kwargs.items loop below wants a comma delimeted string + # that can go right through to the command. kwargs['groups'] = ",".join(groups) else: groups = groups.split(",") - if create_groups: - for group in kwargs.get('groups').split(","): + if create_groups and groups: + for group in groups: if not util.is_group(group): self.create_group(group) LOG.debug("created group %s for user %s", name, group) -- cgit v1.2.3 From 2c95e4cf2a61d13de72833c79d04648ba1687ef9 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 6 Apr 2016 11:03:55 -0400 Subject: support adding the primary group also --- cloudinit/distros/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index 5563ae43..71da7ec5 100644 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -371,6 +371,10 @@ class Distro(object): kwargs['groups'] = ",".join(groups) else: groups = groups.split(",") + + primary_group = kwargs.get('primary_group') + if primary_group: + groups.append(primary_group) if create_groups and groups: for group in groups: -- cgit v1.2.3