diff options
Diffstat (limited to 'system/group.py')
-rw-r--r-- | system/group.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/system/group.py b/system/group.py index f6628727..ceffd753 100644 --- a/system/group.py +++ b/system/group.py @@ -53,7 +53,9 @@ options: EXAMPLES = ''' # Example group command from Ansible Playbooks -- group: name=somegroup state=present +- group: + name: somegroup + state: present ''' import grp @@ -144,7 +146,7 @@ class SunOS(Group): This overrides the following methods from the generic class:- - group_add() - """ + """ platform = 'SunOS' distribution = None @@ -269,6 +271,11 @@ class DarwinGroup(Group): cmd += [ '-o', 'create' ] if self.gid is not None: cmd += [ '-i', self.gid ] + elif 'system' in kwargs and kwargs['system'] == True: + gid = self.get_lowest_available_system_gid() + if gid != False: + self.gid = str(gid) + cmd += [ '-i', self.gid ] cmd += [ '-L', self.name ] (rc, out, err) = self.execute_command(cmd) return (rc, out, err) @@ -291,6 +298,26 @@ class DarwinGroup(Group): (rc, out, err) = self.execute_command(cmd) return (rc, out, err) return (None, '', '') + + def get_lowest_available_system_gid(self): + # check for lowest available system gid (< 500) + try: + cmd = [self.module.get_bin_path('dscl', True)] + cmd += [ '/Local/Default', '-list', '/Groups', 'PrimaryGroupID'] + (rc, out, err) = self.execute_command(cmd) + lines = out.splitlines() + highest = 0 + for group_info in lines: + parts = group_info.split(' ') + if len(parts) > 1: + gid = int(parts[-1]) + if gid > highest and gid < 500: + highest = gid + if highest == 0 or highest == 499: + return False + return (highest + 1) + except: + return False class OpenBsdGroup(Group): """ |