1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-05-11 04:04:13 +00:00

pam_limits: only create backup file when content actually changes (#12014)

* fix(pam_limits): only create backup when file is actually changed

Fixes #12011

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* changelog: add fragment for PR 12014

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Alexei Znamensky 2026-05-10 11:41:06 +12:00 committed by GitHub
parent 798439f1fe
commit b8659f5c61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "pam_limits - only create backup file when the target file is actually modified (https://github.com/ansible-collections/community.general/issues/12011, https://github.com/ansible-collections/community.general/pull/12014)."

View file

@ -235,10 +235,7 @@ def main():
_assert_is_valid_value(module, limit_item, value)
# Backup
if backup:
backup_file = module.backup_local(limits_conf)
backup_file = None
space_pattern = re.compile(r"\s+")
if does_not_exist:
@ -356,6 +353,9 @@ def main():
with open(limits_conf, "a"):
pass
if backup and changed and not does_not_exist:
backup_file = module.backup_local(limits_conf)
# Move tempfile to newfile
module.atomic_move(os.path.abspath(nf.name), os.path.abspath(limits_conf))
@ -370,7 +370,7 @@ def main():
diff=dict(before=b"".join(lines), after=content_new),
)
if backup:
if backup_file:
res_args["backup_file"] = backup_file
module.exit_json(**res_args)