From 4d7d7e16e83448cce014d818fa20cd1efb1be278 Mon Sep 17 00:00:00 2001 From: Gonéri Le Bouder Date: Tue, 7 Jan 2020 12:06:38 -0500 Subject: 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 --- cloudinit/distros/freebsd.py | 29 +++++++++++++++-------------- 1 file 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): -- cgit v1.2.3