From d977da5b41f34933ca11c69d3af766f8ec283b55 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Mon, 13 Jul 2015 11:06:03 -0400 Subject: [PATCH] Fixing up fact_cache use in VariableManager --- lib/ansible/plugins/cache/jsonfile.py | 2 +- lib/ansible/vars/__init__.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/ansible/plugins/cache/jsonfile.py b/lib/ansible/plugins/cache/jsonfile.py index 356d899325e..08c57018cbb 100644 --- a/lib/ansible/plugins/cache/jsonfile.py +++ b/lib/ansible/plugins/cache/jsonfile.py @@ -73,7 +73,7 @@ class CacheModule(BaseCacheModule): except ValueError: # FIXME: this is in display now, but cache plugins don't have that #utils.warning("error while trying to write to %s : %s" % (cachefile, str(e))) - return dict() + raise KeyError finally: f.close() diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py index 591066e0785..0f1561b5a21 100644 --- a/lib/ansible/vars/__init__.py +++ b/lib/ansible/vars/__init__.py @@ -181,7 +181,10 @@ class VariableManager: all_vars = self._combine_vars(all_vars, host.get_vars()) # next comes the facts cache and the vars cache, respectively - all_vars = self._combine_vars(all_vars, self._fact_cache.get(host.get_name(), dict())) + try: + all_vars = self._combine_vars(all_vars, self._fact_cache.get(host.name, dict())) + except KeyError: + pass if play: all_vars = self._combine_vars(all_vars, play.get_vars()) @@ -345,11 +348,13 @@ class VariableManager: assert isinstance(facts, dict) - host_name = host.get_name() - if host_name not in self._fact_cache: - self._fact_cache[host_name] = facts + if host.name not in self._fact_cache: + self._fact_cache[host.name] = facts else: - self._fact_cache[host_name].update(facts) + try: + self._fact_cache[host.name].update(facts) + except KeyError: + self._fact_cache[host.name] = facts def set_host_variable(self, host, varname, value): '''