Fix fact deps when 'filter=ansible_fact' is used. (#33441)

The accumulated collected_facts was being update
with new facts _after_ filtering them. So only
facts that pass the filter would ever be passed
to other fact collectors.

For 'filter=ansible_service_mgr', even though it requires
the platform and distribution facts and even collects them,
they would get filtered out and never passed to the other
collectors that need them (service_mgr for ex).

Fix is just to add the unfiltered facts to collected_facts.

Adds unit tests for fact filter and collected_facts.

Fixes #32286
This commit is contained in:
Adrian Likins
2018-01-20 15:07:27 -05:00
committed by GitHub
parent ec9769c82f
commit 08f92a9f0f
2 changed files with 156 additions and 6 deletions

View File

@@ -67,10 +67,6 @@ class AnsibleFactCollector(collector.BaseFactCollector):
for collector_obj in self.collectors:
info_dict = {}
# shallow copy of the accumulated collected facts to pass to each collector
# for reference.
collected_facts.update(facts_dict.copy())
try:
# Note: this collects with namespaces, so collected_facts also includes namespaces
@@ -80,6 +76,10 @@ class AnsibleFactCollector(collector.BaseFactCollector):
sys.stderr.write(repr(e))
sys.stderr.write('\n')
# shallow copy of the new facts to pass to each collector in collected_facts so facts
# can reference other facts they depend on.
collected_facts.update(info_dict.copy())
# NOTE: If we want complicated fact dict merging, this is where it would hook in
facts_dict.update(self._filter(info_dict, self.filter_spec))