From bd6594e321f238b5dbd501440c8556308264f415 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 9 Apr 2025 16:43:58 -0400 Subject: [PATCH] needed intesect, not difference (#84839) (#84859) fixes #84750 Added tests to verify output when using smart + others (cherry picked from commit 0d4f00f5c89901e53c2f9c32fa87acac3fed8118) --- changelogs/fragments/gather_facts_smart_fix.yml | 2 ++ lib/ansible/plugins/action/gather_facts.py | 2 +- test/integration/targets/gathering_facts/runme.sh | 3 +++ .../targets/gathering_facts/smart_added.yml | 11 +++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/gather_facts_smart_fix.yml create mode 100644 test/integration/targets/gathering_facts/smart_added.yml diff --git a/changelogs/fragments/gather_facts_smart_fix.yml b/changelogs/fragments/gather_facts_smart_fix.yml new file mode 100644 index 00000000000..c6100d0844c --- /dev/null +++ b/changelogs/fragments/gather_facts_smart_fix.yml @@ -0,0 +1,2 @@ +bugfixes: + - gather_facts action, will now add setup when 'smart' appears with other modules in the FACTS_MODULES setting (#84750). diff --git a/lib/ansible/plugins/action/gather_facts.py b/lib/ansible/plugins/action/gather_facts.py index b9a1c7992b0..fa3f840bcc7 100644 --- a/lib/ansible/plugins/action/gather_facts.py +++ b/lib/ansible/plugins/action/gather_facts.py @@ -95,7 +95,7 @@ class ActionModule(ActionBase): self._display.warning("Detected 'setup' module and a network OS is set, the output when running it will reflect 'localhost'" " and not the target when a netwoking connection plugin is used.") - elif not set(modules).difference(set(C._ACTION_SETUP)): + elif not set(modules).intersection(set(C._ACTION_SETUP)): # no network OS and setup not in list, add setup by default since 'smart' modules.append('ansible.legacy.setup') diff --git a/test/integration/targets/gathering_facts/runme.sh b/test/integration/targets/gathering_facts/runme.sh index b1d2e8abb06..fe3714e0fe7 100755 --- a/test/integration/targets/gathering_facts/runme.sh +++ b/test/integration/targets/gathering_facts/runme.sh @@ -45,4 +45,7 @@ ANSIBLE_FACTS_MODULES='smart' ansible -m gather_facts localhost -e 'ansible_netw # ensure we warn on setup + network OS ANSIBLE_FACTS_MODULES='smart, setup' ansible -m gather_facts localhost -e 'ansible_network_os="N/A"' "$@" 2>&1 | grep "Detected 'setup' module and a network OS is set" +# ensure run setup when smart+ and no network OS +ANSIBLE_FACTS_MODULES='smart, facts_one' ansible-playbook smart_added.yml -i inventory "$@" + rm "${OUTPUT_DIR}/canary.txt" diff --git a/test/integration/targets/gathering_facts/smart_added.yml b/test/integration/targets/gathering_facts/smart_added.yml new file mode 100644 index 00000000000..eade7ff63c5 --- /dev/null +++ b/test/integration/targets/gathering_facts/smart_added.yml @@ -0,0 +1,11 @@ +- hosts: facthost0 + tasks: + - name: ensure we ran custom module AND setup.py/smart + assert: + that: + - >- + 'factsone' in ansible_facts + - >- + ansible_facts['factsone'] == "from facts_one module" + - >- + 'os_family' in ansible_facts