Repository: ansible-collections/community.general

Issue:
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 --->

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
@@ -134,8 +134,8 @@
 '''
 
 import os
-import tempfile
 import re
+import tempfile
 
 from ansible.module_utils.basic import AnsibleModule
 from ansible.module_utils._text import to_native


Test patch:
diff --git a/tests/integration/targets/pam_limits/aliases b/tests/integration/targets/pam_limits/aliases
new file mode 100644
--- /dev/null
+++ b/tests/integration/targets/pam_limits/aliases
@@ -0,0 +1,5 @@
+shippable/posix/group1
+skip/aix
+skip/freebsd
+skip/osx
+skip/macos
diff --git a/tests/integration/targets/pam_limits/files/test_pam_limits.conf b/tests/integration/targets/pam_limits/files/test_pam_limits.conf
new file mode 100644
--- /dev/null
+++ b/tests/integration/targets/pam_limits/files/test_pam_limits.conf
@@ -0,0 +1 @@
+# /etc/security/limits.conf
diff --git a/tests/integration/targets/pam_limits/tasks/main.yml b/tests/integration/targets/pam_limits/tasks/main.yml
new file mode 100644
--- /dev/null
+++ b/tests/integration/targets/pam_limits/tasks/main.yml
@@ -0,0 +1,91 @@
+# Test code for the pam_limits module
+# Copyright: (c) 2021, Abhijeet Kasurde <akasurde@redhat.com>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+- name: Set value for temp limit configuration
+  set_fact:
+    test_limit_file: "/tmp/limits.conf"
+
+- name: Copy temporary limits.conf
+  copy:
+    src: test_pam_limits.conf
+    dest: "{{ test_limit_file }}"
+
+- name: Test check mode support in pam_limits
+  community.general.pam_limits:
+    domain: smith
+    limit_type: soft
+    limit_item: nofile
+    value: '64000'
+    dest: "{{ test_limit_file }}"
+  check_mode: yes
+  register: check_mode_test
+
+- name: Test that check mode is working
+  assert:
+    that:
+      - check_mode_test is changed
+
+- name: Add soft limit for smith user
+  community.general.pam_limits:
+    domain: smith
+    limit_type: soft
+    limit_item: nofile
+    value: '64000'
+    dest: "{{ test_limit_file }}"
+  register: soft_limit_test
+
+- name: Check if changes are made
+  assert:
+    that:
+      - soft_limit_test is changed
+
+- name: Aagin change soft limit for smith user for idempotency
+  community.general.pam_limits:
+    domain: smith
+    limit_type: soft
+    limit_item: nofile
+    value: '64000'
+    dest: "{{ test_limit_file }}"
+  register: soft_limit_test
+
+- name: Check if changes are not made idempotency
+  assert:
+    that:
+      - not soft_limit_test.changed
+
+- name: Change hard limit for Joe user for diff
+  community.general.pam_limits:
+    domain: joe
+    limit_type: hard
+    limit_item: nofile
+    value: '100000'
+    dest: "{{ test_limit_file }}"
+  register: hard_limit_test
+  diff: true
+
+- name: Debugging output for hard limit test
+  debug:
+    msg: "{{ hard_limit_test }}"
+
+- name: Check if changes made
+  assert:
+    that:
+      - hard_limit_test is changed
+      - hard_limit_test.diff.after is defined
+      - hard_limit_test.diff.before is defined
+
+- name: Add comment with change
+  community.general.pam_limits:
+    domain: doom
+    limit_type: hard
+    limit_item: nofile
+    value: '100000'
+    dest: "{{ test_limit_file }}"
+    comment: "This is a nice comment"
+  register: comment_test
+
+- name: Check if changes made
+  assert:
+    that:
+      - comment_test is changed