summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--cloudinit/distros/__init__.py24
-rw-r--r--config/cloud.cfg2
3 files changed, 25 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 6da276b5..da1ca9ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -86,6 +86,8 @@
- Enable password changing via a hashed string [Alex Sirbu]
- Added BigStep datasource [Alex Sirbu]
- No longer run pollinate in seed_random (LP: #1554152)
+ - groups: add defalt user to 'lxd' group. Create groups listed
+ for a user if they do not exist. (LP: #1539317)
0.7.6:
- open 0.7.6
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index a73acae5..e8220985 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -319,6 +319,11 @@ class Distro(object):
LOG.info("User %s already exists, skipping." % name)
return
+ if 'create_groups' in kwargs:
+ create_groups = kwargs.pop('create_groups')
+ else:
+ create_groups = True
+
adduser_cmd = ['useradd', name]
log_adduser_cmd = ['useradd', name]
@@ -346,6 +351,19 @@ class Distro(object):
redact_opts = ['passwd']
+ groups = kwargs.get('groups')
+ if groups:
+ if isinstance(groups, (list, tuple)):
+ kwargs['groups'] = ",".join(groups)
+ else:
+ groups = groups.split(",")
+
+ if create_groups:
+ for group in kwargs.get('groups').split(","):
+ if not util.is_group(group):
+ self.create_group(group)
+ LOG.debug("created group %s for user %s", name, group)
+
# Check the values and create the command
for key, val in kwargs.items():
@@ -534,8 +552,10 @@ class Distro(object):
util.logexc(LOG, "Failed to append sudoers file %s", sudo_file)
raise e
- def create_group(self, name, members):
+ def create_group(self, name, members=None):
group_add_cmd = ['groupadd', name]
+ if not members:
+ members = []
# Check if group exists, and then add it doesn't
if util.is_group(name):
@@ -545,7 +565,7 @@ class Distro(object):
util.subp(group_add_cmd)
LOG.info("Created new group %s" % name)
except Exception:
- util.logexc("Failed to create group %s", name)
+ util.logexc(LOG, "Failed to create group %s", name)
# Add members to the group, if so defined
if len(members) > 0:
diff --git a/config/cloud.cfg b/config/cloud.cfg
index 795df19f..a6afcc83 100644
--- a/config/cloud.cfg
+++ b/config/cloud.cfg
@@ -89,7 +89,7 @@ system_info:
name: ubuntu
lock_passwd: True
gecos: Ubuntu
- groups: [adm, audio, cdrom, dialout, dip, floppy, netdev, plugdev, sudo, video]
+ groups: [adm, audio, cdrom, dialout, dip, floppy, lxd, netdev, plugdev, sudo, video]
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
shell: /bin/bash
# Other config here will be given to the distro class and/or path classes