diff options
author | Gonéri Le Bouder <goneri@lebouder.net> | 2020-01-07 12:06:38 -0500 |
---|---|---|
committer | Daniel Watkins <oddbloke@ubuntu.com> | 2020-01-07 12:06:38 -0500 |
commit | 4d7d7e16e83448cce014d818fa20cd1efb1be278 (patch) | |
tree | 436d64de8849082980d09ac853bf71029427638e /cloudinit | |
parent | 098073de8865a479afa770833dd7a28d1233d294 (diff) | |
download | vyos-cloud-init-4d7d7e16e83448cce014d818fa20cd1efb1be278.tar.gz vyos-cloud-init-4d7d7e16e83448cce014d818fa20cd1efb1be278.zip |
freebsd: fix create_group() cmd (#146)
The correct command to create a group if `pw group add foo`. In
addition, this commit simplify a bit the logic:
- simplify a block to avoid an extra level of indentation
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/distros/freebsd.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py index 95cabc5c..8936bd24 100644 --- a/cloudinit/distros/freebsd.py +++ b/cloudinit/distros/freebsd.py @@ -60,7 +60,7 @@ class Distro(distros.Distro): rhel_util.update_sysconfig_file(filename, {'hostname': hostname}) def create_group(self, name, members): - group_add_cmd = ['pw', '-n', name] + group_add_cmd = ['pw', 'group', 'add', name] if util.is_group(name): LOG.warning("Skipping creation of existing group '%s'", name) else: @@ -70,19 +70,20 @@ class Distro(distros.Distro): except Exception as e: util.logexc(LOG, "Failed to create group %s", name) raise e - - if len(members) > 0: - for member in members: - if not util.is_user(member): - LOG.warning("Unable to add group member '%s' to group '%s'" - "; user does not exist.", member, name) - continue - try: - util.subp(['pw', 'usermod', '-n', name, '-G', member]) - LOG.info("Added user '%s' to group '%s'", member, name) - except Exception: - util.logexc(LOG, "Failed to add user '%s' to group '%s'", - member, name) + if not members: + members = [] + + for member in members: + if not util.is_user(member): + LOG.warning("Unable to add group member '%s' to group '%s'" + "; user does not exist.", member, name) + continue + try: + util.subp(['pw', 'usermod', '-n', name, '-G', member]) + LOG.info("Added user '%s' to group '%s'", member, name) + except Exception: + util.logexc(LOG, "Failed to add user '%s' to group '%s'", + member, name) def add_user(self, name, **kwargs): if util.is_user(name): |