From dcb22d176075fc7045f714bad7c5e59656e9520f Mon Sep 17 00:00:00 2001 From: lonerr Date: Wed, 8 May 2013 13:36:55 +0400 Subject: [PATCH] FreeBSD group operations is now supported properly. --- library/system/group | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/library/system/group b/library/system/group index caa4d417c06..eb93d93c2d6 100644 --- a/library/system/group +++ b/library/system/group @@ -210,6 +210,43 @@ class AIX(Group): # =========================================== +class FreeBsdGroup(Group): + """ + This is a FreeBSD Group manipulation class. + + This overrides the following methods from the generic class:- + - group_del() + - group_add() + - group_mod() + """ + + platform = 'FreeBSD' + distribution = None + GROUPFILE = '/etc/group' + + def group_del(self): + cmd = [self.module.get_bin_path('pw', True), 'groupdel', self.name] + return self.execute_command(cmd) + + def group_add(self,**kwargs): + cmd = [self.module.get_bin_path('pw', True), 'groupadd', self.name] + if self.gid is not None: + cmd.append('-g %d' % int(self.gid)) + return self.execute_command(cmd) + + def group_mod(self,**kwargs): + cmd = [self.module.get_bin_path('pw', True), 'groupmod', self.name] + info = self.group_info() + cmd_len = len(cmd) + if self.gid is not None and int(self.gid) != info[2]: + cmd.append('-g %d' % int(self.gid)) + # modify the group if cmd will do anything + if cmd_len != len(cmd): + return self.execute_command(cmd) + return (None, '', '') + +# =========================================== + def main(): module = AnsibleModule( argument_spec = dict(