From a4cac6f833144c27615f4e3543ae863f9f0f332a Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sat, 13 Jun 2026 17:33:24 +0200 Subject: [PATCH] [PR #12122/b12c21f0 backport][stable-13] launchd: fix `restarted` and `reloaded` always reporting `changed=False` (#12247) launchd: fix `restarted` and `reloaded` always reporting `changed=False` (#12122) * fix(launchd): restarted and reloaded always report changed Both actions unconditionally execute commands (unload/load/start), so changed must always be True in non-check mode, regardless of whether the PID or state happened to match before and after. * feat(changelog): add fragment for PR 12122 * fix(launchd): restarted and reloaded always report changed in check mode too * consolidate if branches --------- (cherry picked from commit b12c21f0ce306217df86f151e8a0d87d5c937b3d) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 --- .../fragments/12122-launchd-restarted-always-changed.yml | 4 ++++ plugins/modules/launchd.py | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/12122-launchd-restarted-always-changed.yml diff --git a/changelogs/fragments/12122-launchd-restarted-always-changed.yml b/changelogs/fragments/12122-launchd-restarted-always-changed.yml new file mode 100644 index 0000000000..ef9fe577a3 --- /dev/null +++ b/changelogs/fragments/12122-launchd-restarted-always-changed.yml @@ -0,0 +1,4 @@ +bugfixes: + - "launchd - fix ``restarted`` and ``reloaded`` states always reporting ``changed=False`` + (https://github.com/ansible-collections/community.general/issues/6199, + https://github.com/ansible-collections/community.general/pull/12122)." diff --git a/plugins/modules/launchd.py b/plugins/modules/launchd.py index 64a1375a40..3848bf2c6f 100644 --- a/plugins/modules/launchd.py +++ b/plugins/modules/launchd.py @@ -507,14 +507,15 @@ def main(): result["status"]["status_code"] = status_code result["status"]["error"] = err + # restarted and reloaded always perform commands unconditionally, so they always change state if ( - result["status"]["current_state"] != result["status"]["previous_state"] + action in ("restarted", "reloaded") + or result["status"]["current_state"] != result["status"]["previous_state"] or result["status"]["current_pid"] != result["status"]["previous_pid"] ): result["changed"] = True - if module.check_mode: - if result["status"]["current_state"] != action: - result["changed"] = True + elif module.check_mode and result["status"]["current_state"] != action: + result["changed"] = True module.exit_json(**result)