Repository: ansible-collections/community.general

Issue:
pam_limits: add check mode
<!--- Verify first that your feature was not already discussed on GitHub -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
<!--- Describe the new feature/improvement briefly below -->
**pam_limits** module has no check mode.

##### ISSUE TYPE
- Feature Idea

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->
pam_limits

pam_limits: add diff mode
<!--- Verify first that your feature was not already discussed on GitHub -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
<!--- Describe the new feature/improvement briefly below -->
**pam_limits** module has no diff mode.

##### ISSUE TYPE
- Feature Idea

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->
pam_limits



Discussion:
Files identified in the description:
* [`plugins/modules/system/pam_limits.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/system/pam_limits.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 @MorrisA @bcoca @d-little @flynn1973 @gforster @giovannisciortino @kairoaraujo @marvin-sinister @mator @molekuul @ramooncamacho @wtcross
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Files identified in the description:
* [`plugins/modules/system/pam_limits.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/system/pam_limits.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 @MorrisA @bcoca @d-little @flynn1973 @gforster @giovannisciortino @kairoaraujo @marvin-sinister @mator @molekuul @ramooncamacho @wtcross
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/plugins/modules/system/pam_limits.py b/plugins/modules/system/pam_limits.py
--- a/plugins/modules/system/pam_limits.py
+++ b/plugins/modules/system/pam_limits.py
@@ -154,7 +154,8 @@ def main():
             backup=dict(default=False, type='bool'),
             dest=dict(default=limits_conf, type='str'),
             comment=dict(required=False, default='', type='str')
-        )
+        ),
+        supports_check_mode=True,
     )
 
     domain = module.params['domain']
@@ -289,8 +290,15 @@ def main():
     f.close()
     nf.flush()
 
-    # Copy tempfile to newfile
-    module.atomic_move(nf.name, f.name)
+    with open(limits_conf, 'r') as content:
+        content_current = content.read()
+
+    with open(nf.name, 'r') as content:
+        content_new = content.read()
+
+    if not module.check_mode:
+        # Copy tempfile to newfile
+        module.atomic_move(nf.name, limits_conf)
 
     try:
         nf.close()
@@ -298,7 +306,9 @@ def main():
         pass
 
     res_args = dict(
-        changed=changed, msg=message
+        changed=changed,
+        msg=message,
+        diff=dict(before=content_current, after=content_new),
     )
 
     if backup:


Test patch: