diff --git a/lib/ansible/modules/system/group.py b/lib/ansible/modules/system/group.py index 01fef187c96..ce4ff8a26a2 100644 --- a/lib/ansible/modules/system/group.py +++ b/lib/ansible/modules/system/group.py @@ -43,6 +43,15 @@ options: - If I(yes), indicates that the group created is a system group. type: bool default: 'no' + local: + version_added: "2.5" + required: false + default: 'no' + description: + - Forces the use of "local" command alternatives on platforms that implement it. + This is useful in environments that use centralized authentification when you want to manipulate the local groups. + I.E. it uses `lgroupadd` instead of `useradd`. + - This requires that these commands exist on the targeted host, otherwise it will be a fatal error. notes: - For Windows targets, use the M(win_group) module instead. ''' @@ -85,16 +94,25 @@ class Group(object): self.name = module.params['name'] self.gid = module.params['gid'] self.system = module.params['system'] + self.local = module.params['local'] def execute_command(self, cmd): return self.module.run_command(cmd) def group_del(self): - cmd = [self.module.get_bin_path('groupdel', True), self.name] + if self.local: + command_name = 'lgroupdel' + else: + command_name = 'groupdel' + cmd = [self.module.get_bin_path(command_name, True), self.name] return self.execute_command(cmd) def group_add(self, **kwargs): - cmd = [self.module.get_bin_path('groupadd', True)] + if self.local: + command_name = 'lgroupadd' + else: + command_name = 'groupadd' + cmd = [self.module.get_bin_path(command_name, True)] for key in kwargs: if key == 'gid' and kwargs[key] is not None: cmd.append('-g') @@ -105,7 +123,11 @@ class Group(object): return self.execute_command(cmd) def group_mod(self, **kwargs): - cmd = [self.module.get_bin_path('groupmod', True)] + if self.local: + command_name = 'lgroupmod' + else: + command_name = 'groupmod' + cmd = [self.module.get_bin_path(command_name, True)] info = self.group_info() for key in kwargs: if key == 'gid': @@ -419,6 +441,7 @@ def main(): name=dict(type='str', required=True), gid=dict(type='str'), system=dict(type='bool', default=False), + local=dict(type='bool', default=False) ), supports_check_mode=True, )