added 'local' option to group (#34805)
* added 'local' option to group fixes #34804' * fix to version 2.5 fixes #34804' * fix missing local var
This commit is contained in:
parent
aa09ed1a88
commit
54e0327e5d
1 changed files with 26 additions and 3 deletions
|
@ -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,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue