diff --git a/changelogs/fragments/vm_fix.yml b/changelogs/fragments/vm_fix.yml new file mode 100644 index 00000000000..29bd711dc7d --- /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 8a8efc13ef5..cb58ed63fcb 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): '''