From fb50698da32f36aaff5359f466679a7b8ff3f80b Mon Sep 17 00:00:00 2001 From: cinerama70 Date: Wed, 28 Sep 2016 16:24:32 -0700 Subject: [PATCH] Graceful error handling when delegate_to host null (#17453) (#17783) Currently, if the host specified in delegate_to for a task is null, Ansible will crash with a stack trace. Add a check for this state and handle the error appropriately. --- lib/ansible/vars/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py index b50fb22712..6e918d70e2 100644 --- a/lib/ansible/vars/__init__.py +++ b/lib/ansible/vars/__init__.py @@ -459,6 +459,8 @@ class VariableManager: templar.set_available_variables(vars_copy) delegated_host_name = templar.template(task.delegate_to, fail_on_undefined=False) + if not delegated_host_name: + raise AnsibleError(message="Undefined delegate_to host for task:", obj=task._ds) if delegated_host_name in delegated_host_vars: # no need to repeat ourselves, as the delegate_to value # does not appear to be tied to the loop item variable