From 7da478a4f42ae2f3eace2cc7a201f48e3cae8115 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Fri, 9 Oct 2015 11:16:41 -0400 Subject: [PATCH] Fix an issue where cache plugins weren't updated The first call to persisting facts would work due to the assignment of a MutableMapping calling __setitem__ but subsequent module fact data would not be propogated to the fact cache plugins because update() doesn't invoke __setitem__. This changes the behavior a little bit and ensures set() is called on cache plugins. --- lib/ansible/plugins/cache/__init__.py | 5 +++++ lib/ansible/vars/__init__.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/cache/__init__.py b/lib/ansible/plugins/cache/__init__.py index 0938e0983e6..875837d0337 100644 --- a/lib/ansible/plugins/cache/__init__.py +++ b/lib/ansible/plugins/cache/__init__.py @@ -68,3 +68,8 @@ class FactCache(MutableMapping): def flush(self): """ 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) diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py index ec2ed992228..0988ed80367 100644 --- a/lib/ansible/vars/__init__.py +++ b/lib/ansible/vars/__init__.py @@ -546,7 +546,7 @@ class VariableManager: self._fact_cache[host.name] = facts else: try: - self._fact_cache[host.name].update(facts) + self._fact_cache.update(host.name, facts) except KeyError: self._fact_cache[host.name] = facts