diff options
author | Toshio Kuratomi <a.badger@gmail.com> | 2018-12-05 12:41:57 -0800 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2018-12-06 10:59:32 -0800 |
commit | ad45bd72c1c214e7b126c7709448a140392e963f (patch) | |
tree | 11544a1cfa71f1845baaae127c86a5389d2f7d71 | |
parent | dc9bb38d720b751e78b56d3c45425ae6b2ae6354 (diff) | |
download | ansible-ad45bd72c1c214e7b126c7709448a140392e963f.tar.gz |
Fix for a caching traceback
When the user specified caching plugin doesn't initialize correctly, we
were falling back to a dict. however, dicts do not have the same
update() method as the FactCache. We use the update method when we
update a cache with a subsequent value. So when that combination of
things happened, the code would traceback.
In devel, we made this change to fix things: https://github.com/ansible/ansible/pull/49516
but that involves several deprecations. So we're doing this smaller
hack in 2.7 to fix the traceback without introducing those deprecations
in a stable release.
-rw-r--r-- | changelogs/fragments/vm_fix.yml | 2 | ||||
-rw-r--r-- | lib/ansible/vars/manager.py | 19 |
2 files changed, 17 insertions, 4 deletions
diff --git a/changelogs/fragments/vm_fix.yml b/changelogs/fragments/vm_fix.yml new file mode 100644 index 0000000000..29bd711dc7 --- /dev/null +++ b/changelogs/fragments/vm_fix.yml @@ -0,0 +1,2 @@ +bugfixes: +- Fix traceback when updating facts and the fact cache plugin was nonfunctional diff --git a/lib/ansible/vars/manager.py b/lib/ansible/vars/manager.py index 8a8efc13ef..cb58ed63fc 100644 --- a/lib/ansible/vars/manager.py +++ b/lib/ansible/vars/manager.py @@ -622,10 +622,21 @@ class VariableManager: if host.name not in self._fact_cache: self._fact_cache[host.name] = facts else: - try: - self._fact_cache.update(host.name, facts) - except KeyError: - self._fact_cache[host.name] = facts + if isinstance(self._fact_cache, FactCache): + try: + self._fact_cache.update(host.name, facts) + except KeyError: + self._fact_cache[host.name] = facts + else: + # Dictionary fallback so we need to use a dictionary update. + try: + host_cache = self._fact_cache[host.name] + except KeyError: + host_cache = facts + else: + host_cache.update(facts) + + self._fact_cache[host.name] = host_cache def set_nonpersistent_facts(self, host, facts): ''' |