mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-26 08:26:28 +00:00
Change hostvars to a mutable mapping to more closely resemble a dict
Fixes #4030
This commit is contained in:
@@ -81,13 +81,20 @@ def _executor_hook(job_queue, result_queue, new_stdin):
|
||||
except:
|
||||
traceback.print_exc()
|
||||
|
||||
class HostVars(collections.Mapping):
|
||||
class HostVars(collections.MutableMapping):
|
||||
''' A special view of setup_cache that adds values from the inventory when needed. '''
|
||||
|
||||
def __init__(self, setup_cache, inventory):
|
||||
self.setup_cache = setup_cache
|
||||
self.inventory = inventory
|
||||
self.lookup = {}
|
||||
self.lookup = dict()
|
||||
self.update(setup_cache)
|
||||
|
||||
def __setitem__(self, host, value):
|
||||
self.lookup[host] = value
|
||||
|
||||
def __delitem__(self, host):
|
||||
del self.lookup[host]
|
||||
|
||||
def __getitem__(self, host):
|
||||
if not host in self.lookup:
|
||||
@@ -97,10 +104,10 @@ class HostVars(collections.Mapping):
|
||||
return self.lookup[host]
|
||||
|
||||
def __iter__(self):
|
||||
return (host.name for host in self.inventory.get_group('all').hosts)
|
||||
return iter(self.lookup)
|
||||
|
||||
def __len__(self):
|
||||
return len(self.inventory.get_group('all').hosts)
|
||||
return len(self.lookup)
|
||||
|
||||
|
||||
class Runner(object):
|
||||
|
||||
Reference in New Issue
Block a user