mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
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:
@@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user