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)