diff --git a/lib/ansible/cache/base.py b/lib/ansible/cache/base.py index 9a382851615..b6254cdfd48 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 35c6d9970ec..ea922434b50 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 e9a151d1290..735ed32893e 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 9b0cfaaecbb..a80cbd9d83e 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 7500eea11e0..8a50f9e02d5 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)