Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added 'local' option to group #34805

Merged
merged 3 commits into from
Feb 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 26 additions & 3 deletions lib/ansible/modules/system/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@
- 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.
'''
Expand Down Expand Up @@ -85,16 +94,25 @@ def __init__(self, module):
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')
Expand All @@ -105,7 +123,11 @@ def group_add(self, **kwargs):
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':
Expand Down Expand Up @@ -410,6 +432,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,
)
Expand Down