Skip to content

Commit

Permalink
Fixing up fact_cache use in VariableManager
Browse files Browse the repository at this point in the history
  • Loading branch information
jimi-c committed Jul 13, 2015
1 parent 932d1e5 commit d977da5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/ansible/plugins/cache/jsonfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get(self, key):
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()

Expand Down
15 changes: 10 additions & 5 deletions lib/ansible/vars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ def get_vars(self, loader, play=None, host=None, task=None, use_cache=True):
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())
Expand Down Expand Up @@ -345,11 +348,13 @@ def set_host_facts(self, host, facts):

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):
'''
Expand Down

0 comments on commit d977da5

Please sign in to comment.