From 2e628f98956b4ecc28489b205bd29dace09364ae Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sat, 30 May 2026 20:29:37 +0200 Subject: [PATCH] [PR #12113/ef5b22d1 backport][stable-12] unixy callback: fix KeyError when task is delegated to host without ansible_host set (#12142) unixy callback: fix KeyError when task is delegated to host without ansible_host set (#12113) * fixes issue #12112 * adjust PR ID * adjust PR ID, mistake was made * adjust PR ID * I messed up all these numbers --------- (cherry picked from commit ef5b22d18e5549395bb836f4ff17da179c90b0fd) Co-authored-by: Stefan Midjich Co-authored-by: Stefan Midjich --- changelogs/fragments/12113-unixy-delegated-host.yml | 2 ++ plugins/callback/unixy.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/12113-unixy-delegated-host.yml diff --git a/changelogs/fragments/12113-unixy-delegated-host.yml b/changelogs/fragments/12113-unixy-delegated-host.yml new file mode 100644 index 0000000000..dae29b6b2e --- /dev/null +++ b/changelogs/fragments/12113-unixy-delegated-host.yml @@ -0,0 +1,2 @@ +bugfixes: + - "unixy callback - handle missing ``ansible_host`` in delegated vars when a task is delegated to a host without it set, such as ``localhost`` (https://github.com/ansible-collections/community.general/issues/12112, https://github.com/ansible-collections/community.general/pull/12113)." diff --git a/plugins/callback/unixy.py b/plugins/callback/unixy.py index f264eb3e0a..2c3f9a9392 100644 --- a/plugins/callback/unixy.py +++ b/plugins/callback/unixy.py @@ -74,7 +74,7 @@ class CallbackModule(CallbackModule_default): return task_result if self.delegated_vars: - task_delegate_host = self.delegated_vars["ansible_host"] + task_delegate_host = self.delegated_vars.get("ansible_host") or result._task.delegate_to or "" task_result = f"{task_host} -> {task_delegate_host} {msg}" if result._result.get("msg") and result._result.get("msg") != "All items completed":