From 777d36b9fbfce838de0890f46c266645fe8fad54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=99=AB=20Christian=20Krause=20=E2=99=AB?= Date: Sun, 3 Jan 2021 11:11:06 +0100 Subject: [PATCH] pam_limits: adds both check and diff modes (#830) * pam_limits: adds check mode fixes #827 * pam_limits: adds diff mode fixes #828 --- changelogs/fragments/830-pam-limits.yml | 3 +++ plugins/modules/system/pam_limits.py | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/830-pam-limits.yml diff --git a/changelogs/fragments/830-pam-limits.yml b/changelogs/fragments/830-pam-limits.yml new file mode 100644 index 0000000000..28b5ee3dc0 --- /dev/null +++ b/changelogs/fragments/830-pam-limits.yml @@ -0,0 +1,3 @@ +minor_changes: + - pam_limits - adds check mode (https://github.com/ansible-collections/community.general/issues/827). + - pam_limits - adds diff mode (https://github.com/ansible-collections/community.general/issues/828). diff --git a/plugins/modules/system/pam_limits.py b/plugins/modules/system/pam_limits.py index 5c74f1c035..35a896af71 100644 --- a/plugins/modules/system/pam_limits.py +++ b/plugins/modules/system/pam_limits.py @@ -176,7 +176,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'] @@ -315,8 +316,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() @@ -324,7 +332,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: