From 10afaee108f9fd04ad45155b7977144304d77a1d Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Tue, 9 Sep 2014 15:35:08 -0500 Subject: [PATCH] Fixing new caching related issue with host vars The vars_cache was not being properly merged with the setup_cache for all hosts, which was previously not noticed when registered variables were stored in the setup_cache. Fixes #8944 --- lib/ansible/cache/base.py | 3 +++ lib/ansible/cache/memcached.py | 3 +++ lib/ansible/cache/memory.py | 7 ++++++- lib/ansible/cache/redis.py | 7 +++++++ lib/ansible/runner/__init__.py | 2 +- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/ansible/cache/base.py b/lib/ansible/cache/base.py index 9a38285161..b6254cdfd4 100644 --- a/lib/ansible/cache/base.py +++ b/lib/ansible/cache/base.py @@ -36,3 +36,6 @@ class BaseCacheModule(object): def flush(self): raise exceptions.NotImplementedError + + def copy(self): + raise exceptions.NotImplementedError diff --git a/lib/ansible/cache/memcached.py b/lib/ansible/cache/memcached.py index 35c6d9970e..ea922434b5 100644 --- a/lib/ansible/cache/memcached.py +++ b/lib/ansible/cache/memcached.py @@ -186,3 +186,6 @@ class CacheModule(BaseCacheModule): def flush(self): for key in self.keys(): self.delete(key) + + def copy(self): + return self._keys.copy() diff --git a/lib/ansible/cache/memory.py b/lib/ansible/cache/memory.py index e9a151d129..735ed32893 100644 --- a/lib/ansible/cache/memory.py +++ b/lib/ansible/cache/memory.py @@ -15,7 +15,9 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -class CacheModule(object): +from ansible.cache.base import BaseCacheModule + +class CacheModule(BaseCacheModule): def __init__(self, *args, **kwargs): self._cache = {} @@ -37,3 +39,6 @@ class CacheModule(object): def flush(self): self._cache = {} + + def copy(self): + return self._cache.copy() diff --git a/lib/ansible/cache/redis.py b/lib/ansible/cache/redis.py index 9b0cfaaecb..a80cbd9d83 100644 --- a/lib/ansible/cache/redis.py +++ b/lib/ansible/cache/redis.py @@ -93,3 +93,10 @@ class CacheModule(BaseCacheModule): def flush(self): for key in self.keys(): self.delete(key) + + def copy(self): + # FIXME: there is probably a better way to do this in redis + ret = dict() + for key in self.keys(): + ret[key] self.get(key) + return ret diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 7500eea11e..8a50f9e02d 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -598,7 +598,7 @@ class Runner(object): # merge the VARS and SETUP caches for this host combined_cache = self.setup_cache.copy() - combined_cache.setdefault(host, {}).update(self.vars_cache.get(host, {})) + combined_cache.update(self.vars_cache) hostvars = HostVars(combined_cache, self.inventory, vault_password=self.vault_pass)