diff options
author | Scott Moser <smoser@ubuntu.com> | 2016-04-06 11:23:47 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2016-04-06 11:23:47 -0400 |
commit | d75a912fb375afbab055db3178966d1f83b44143 (patch) | |
tree | 2d537da844bd065f6f318a48844255c136db19d3 /cloudinit | |
parent | 6a660b490ee6384055d2afb07f8cac1628168ba2 (diff) | |
parent | 2c95e4cf2a61d13de72833c79d04648ba1687ef9 (diff) | |
download | vyos-cloud-init-d75a912fb375afbab055db3178966d1f83b44143.tar.gz vyos-cloud-init-d75a912fb375afbab055db3178966d1f83b44143.zip |
fix adding of users when no group is specified
revision 1179 regressed adding a user that did not have a 'groups'
entry present in cloud-config.
This handles that correctly, making 'add_user' able to take:
a.) groups="group1,group2"
b.) groups=["group1", "group2"]
c.) groups=None
d.) no groups parameter
Additionally, if a primary group is specified it will also be created.
End result is that this is functional:
#cloud-config
groups: ["sudo"]
users:
- name: sysop
primary-group: sysop
groups: "sudo,adm"
shell: /bin/bash
- name: user1
primary-group: users
groups: sudo
- name: foo1
- name: bar
gecos: Bar
groups: ["bargroup"]
Resulting in:
$ groups sysop
sysop : sysop adm sudo
$ groups user1
user1 : users sudo
$ groups foo1
foo1 : foo1
$ groups bar
bar : bar bargroup
LP: #1562918
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/distros/__init__.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index 12983c0a..5879dabf 100644 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -362,15 +362,22 @@ 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(","): + primary_group = kwargs.get('primary_group') + if primary_group: + groups.append(primary_group) + + 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) |