1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge branch 'pulls/fix-hostvars-inconsistancy' of https://github.com/ferringb/ansible into ferringb-pulls/fix-hostvars-inconsistancy

This commit is contained in:
James Cammarata 2013-08-22 13:56:34 -05:00
commit 462cd4f728

View file

@ -82,7 +82,7 @@ def _executor_hook(job_queue, result_queue, new_stdin):
except:
traceback.print_exc()
class HostVars(dict):
class HostVars(collections.Mapping):
''' A special view of setup_cache that adds values from the inventory when needed. '''
def __init__(self, setup_cache, inventory):
@ -90,8 +90,6 @@ class HostVars(dict):
self.inventory = inventory
self.lookup = {}
self.update(setup_cache)
def __getitem__(self, host):
if not host in self.lookup:
result = self.inventory.get_variables(host)
@ -99,8 +97,12 @@ class HostVars(dict):
self.lookup[host] = result
return self.lookup[host]
def __contains__(self, host):
return host in self.lookup or host in self.setup_cache or self.inventory.get_host(host)
def __iter__(self):
return (host.name for host in self.inventory.get_group('all').hosts)
def __len__(self):
return len(self.inventory.get_group('all').hosts)
class Runner(object):
''' core API interface to ansible '''