From 164d518370b18b3ff0963f5aa05ec6d8e3d959d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gross?= Date: Thu, 28 Aug 2014 23:24:32 +0200 Subject: [PATCH] Add basic support for OSX groups. --- lib/ansible/modules/system/group.py | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) mode change 100644 => 100755 lib/ansible/modules/system/group.py diff --git a/lib/ansible/modules/system/group.py b/lib/ansible/modules/system/group.py old mode 100644 new mode 100755 index 617de7c2857..83ea410b0b1 --- a/lib/ansible/modules/system/group.py +++ b/lib/ansible/modules/system/group.py @@ -251,6 +251,49 @@ class FreeBsdGroup(Group): # =========================================== + + +class DarwinGroup(Group): + """ + This is a Mac OS X Darwin Group manipulation class. + + This overrides the following methods from the generic class:- + - group_del() + - group_add() + - group_mod() + + group manupulation are done using dseditgroup(1). + """ + + platform = 'Darwin' + distribution = None + + def group_add(self, **kwargs): + cmd = [self.module.get_bin_path('dseditgroup', True)] + cmd += [ '-o', 'create' ] + cmd += [ '-i', self.gid ] + cmd += [ '-L', self.name ] + (rc, out, err) = self.execute_command(cmd) + return (rc, out, err) + + def group_del(self): + cmd = [self.module.get_bin_path('dseditgroup', True)] + cmd += [ '-o', 'delete' ] + cmd += [ '-L', self.name ] + (rc, out, err) = self.execute_command(cmd) + return (rc, out, err) + + def group_mod(self): + info = self.group_info() + if self.gid is not None and int(self.gid) != info[2]: + cmd = [self.module.get_bin_path('dseditgroup', True)] + cmd += [ '-o', 'edit' ] + cmd += [ '-i', self.gid ] + cmd += [ '-L', self.name ] + (rc, out, err) = self.execute_command(cmd) + return (rc, out, err) + return (None, '', '') + class OpenBsdGroup(Group): """ This is a OpenBSD Group manipulation class.