From 291f07242cb59457687eede689a7948c41c68d2c Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Wed, 15 Jul 2015 14:36:42 -0400 Subject: [PATCH] Properly return Jinja2 Undefined class for bad hostvars lookups Fixes #11176 --- lib/ansible/vars/hostvars.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/ansible/vars/hostvars.py b/lib/ansible/vars/hostvars.py index 9d2c3864893..29d1e1aa806 100644 --- a/lib/ansible/vars/hostvars.py +++ b/lib/ansible/vars/hostvars.py @@ -19,6 +19,8 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +from jinja2 import Undefined as j2undefined + from ansible.template import Templar __all__ = ['HostVars'] @@ -37,6 +39,8 @@ class HostVars(dict): if host_name not in self._lookup: host = self._inventory.get_host(host_name) + if not host: + return j2undefined result = self._vars_manager.get_vars(loader=self._loader, play=self._play, host=host) templar = Templar(variables=result, loader=self._loader) self._lookup[host_name] = templar.template(result, fail_on_undefined=False)