mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
fix cache 'update' method to be 'mapping' compatible
- also simplify the update functions - fix methods and allwow backwards compat with plugins overriding 'update'
This commit is contained in:
parent
9973bea504
commit
68301f890a
3 changed files with 27 additions and 18 deletions
18
lib/ansible/plugins/cache/__init__.py
vendored
18
lib/ansible/plugins/cache/__init__.py
vendored
|
@ -292,10 +292,18 @@ class FactCache(MutableMapping):
|
|||
""" Flush the fact cache of all keys. """
|
||||
self._plugin.flush()
|
||||
|
||||
def update(self, key, value):
|
||||
host_cache = self._plugin.get(key)
|
||||
host_cache.update(value)
|
||||
self._plugin.set(key, host_cache)
|
||||
def update(self, host_facts):
|
||||
""" We override the normal update to ensure we always use the 'setter' method """
|
||||
for key in host_facts:
|
||||
try:
|
||||
host_cache = self._plugin.get(key)
|
||||
if host_cache:
|
||||
host_cache.update(host_facts[key])
|
||||
else:
|
||||
host_cache = host_facts[key]
|
||||
self._plugin.set(key, host_cache)
|
||||
except KeyError:
|
||||
self._plugin.set(key, host_facts[key])
|
||||
|
||||
|
||||
class InventoryFileCacheModule(BaseFileCacheModule):
|
||||
|
@ -314,7 +322,7 @@ class InventoryFileCacheModule(BaseFileCacheModule):
|
|||
def validate_cache_connection(self):
|
||||
try:
|
||||
super(InventoryFileCacheModule, self).validate_cache_connection()
|
||||
except AnsibleError as e:
|
||||
except AnsibleError:
|
||||
cache_connection_set = False
|
||||
else:
|
||||
cache_connection_set = True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue