Repository: ansible/ansible

Issue:
Force group creation to be local 
##### ISSUE TYPE
 - Feature Idea

##### COMPONENT NAME
group module

##### ANSIBLE VERSION
N.A.

##### OS / ENVIRONMENT
- RHEL/CENTOS 7

##### SUMMARY
As already applied and merged for user module (#22140), I would like to add the option force=yes to the group module such that is used grouped instead of groupadd.



Discussion:
Files identified in the description:
* [lib/ansible/modules/system/group.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/system/group.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @sfromm
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/system/group.py b/lib/ansible/modules/system/group.py
--- a/lib/ansible/modules/system/group.py
+++ b/lib/ansible/modules/system/group.py
@@ -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.
 '''
@@ -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')
@@ -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':
@@ -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,
     )


Test patch: