added 'local' option to group (#34805)

* added 'local' option to group

fixes #34804'

* fix to version 2.5

fixes #34804'

* fix missing local var
pull/35937/head
Giorgio Crivellari 6 years ago committed by Brian Coca
parent aa09ed1a88
commit 54e0327e5d

@ -43,6 +43,15 @@ options:
- If I(yes), indicates that the group created is a system group. - If I(yes), indicates that the group created is a system group.
type: bool type: bool
default: 'no' 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: notes:
- For Windows targets, use the M(win_group) module instead. - For Windows targets, use the M(win_group) module instead.
''' '''
@ -85,16 +94,25 @@ class Group(object):
self.name = module.params['name'] self.name = module.params['name']
self.gid = module.params['gid'] self.gid = module.params['gid']
self.system = module.params['system'] self.system = module.params['system']
self.local = module.params['local']
def execute_command(self, cmd): def execute_command(self, cmd):
return self.module.run_command(cmd) return self.module.run_command(cmd)
def group_del(self): 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) return self.execute_command(cmd)
def group_add(self, **kwargs): 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: for key in kwargs:
if key == 'gid' and kwargs[key] is not None: if key == 'gid' and kwargs[key] is not None:
cmd.append('-g') cmd.append('-g')
@ -105,7 +123,11 @@ class Group(object):
return self.execute_command(cmd) return self.execute_command(cmd)
def group_mod(self, **kwargs): 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() info = self.group_info()
for key in kwargs: for key in kwargs:
if key == 'gid': if key == 'gid':
@ -419,6 +441,7 @@ def main():
name=dict(type='str', required=True), name=dict(type='str', required=True),
gid=dict(type='str'), gid=dict(type='str'),
system=dict(type='bool', default=False), system=dict(type='bool', default=False),
local=dict(type='bool', default=False)
), ),
supports_check_mode=True, supports_check_mode=True,
) )

Loading…
Cancel
Save