summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Cammarata <jimi@sngx.net>2016-11-21 02:03:16 -0600
committerJames Cammarata <jimi@sngx.net>2016-11-21 12:22:56 -0600
commita34793d7fba3bee813a3ad9d070183ef0639fa47 (patch)
treede7e945aee56d4cf897070029695c0f8d279bc21
parenta91788e25a96db9fe2a0f55173908cfeaa1fe20c (diff)
downloadansible-a34793d7fba3bee813a3ad9d070183ef0639fa47.tar.gz
When iterating over hostvars yield the hostname not the host object
Also fixes HostVars to raise the correct jinja2 error type. Fixes #16836 (cherry picked from commit 0df3767d4d6a522141d6916e5bbe4babe3e4929b)
-rw-r--r--lib/ansible/vars/hostvars.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/ansible/vars/hostvars.py b/lib/ansible/vars/hostvars.py
index 36adf54906..74262b2ed4 100644
--- a/lib/ansible/vars/hostvars.py
+++ b/lib/ansible/vars/hostvars.py
@@ -21,7 +21,7 @@ __metaclass__ = type
import collections
-from jinja2 import Undefined as j2undefined
+from jinja2.exceptions import UndefinedError
from ansible import constants as C
from ansible.template import Templar
@@ -73,7 +73,7 @@ class HostVars(collections.Mapping):
'''
host = self._find_host(host_name)
if host is None:
- raise j2undefined
+ raise UndefinedError("%s not found in hostvars" % host_name)
return self._variable_manager.get_vars(loader=self._loader, host=host, include_hostvars=False)
@@ -102,7 +102,7 @@ class HostVars(collections.Mapping):
def __iter__(self):
for host in self._inventory.get_hosts(ignore_limits=True, ignore_restrictions=True):
- yield host
+ yield host.name
def __len__(self):
return len(self._inventory.get_hosts(ignore_limits=True, ignore_restrictions=True))