From b12c21f0ce306217df86f151e8a0d87d5c937b3d Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Sun, 14 Jun 2026 03:08:41 +1200 Subject: [PATCH] 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. Co-Authored-By: Claude Sonnet 4.6 * feat(changelog): add fragment for PR 12122 Co-Authored-By: Claude Sonnet 4.6 * fix(launchd): restarted and reloaded always report changed in check mode too Co-Authored-By: Claude Sonnet 4.6 * consolidate if branches --------- 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)