fix: read facts through ansible_facts and run Molecule with fact injection off
Build / build (pull_request) Successful in 34s
Lint / lint (pull_request) Successful in 2m32s
Molecule / molecule (pull_request) Canceled after 6m34s

ansible-core deprecates injecting facts as top-level variables (removal is
scheduled for 2.24, see #364). Three roles still read a bare fact: system_baseline (reboot check,
ansible_os_family), docker (APT source line, ansible_distribution_release)
and gitea_runner (re-registration backup name, ansible_date_time). With
inject_facts_as_vars set to false the system_baseline reboot check failed
with "'ansible_os_family' is undefined".

They now read ansible_facts[...]; the argument specs and READMEs that name
the facts follow. run_molecule_in_ci_image.sh exports
ANSIBLE_INJECT_FACT_VARS=False, so a role that reads an injected fact fails
its scenario, and a script test keeps the export in place.

Refs #364

Assisted-by: Claude Code:claude-sonnet-5-5
This commit is contained in:
Dragonish committed 2026-11-26 21:33:03 +00:00
1 parent 9c415ee347
commit 26b6e37a09
12 files changed
+41 -13

No files matched your search

+11 -1
View File
@@ -42,7 +42,7 @@ exit 0
# The scenario runner: records its arguments, paths and stdin.
RUNNER_STUB = """#!/usr/bin/env bash
echo "runner args=$* path=$PATH acp=$ANSIBLE_COLLECTIONS_PATH stdin=[$(cat | tr '\\n' ' ')]" >> "$STUB_LOG"
echo "runner args=$* path=$PATH acp=$ANSIBLE_COLLECTIONS_PATH inject=${ANSIBLE_INJECT_FACT_VARS-unset} stdin=[$(cat | tr '\\n' ' ')]" >> "$STUB_LOG"
"""
@@ -112,6 +112,16 @@ class RunMoleculeInCiImageTest(unittest.TestCase):
self.assertIn(f"acp={self.ac_root}:/opt/collections ", runner)
self.assertIn(f"args={self.ac_root}/molecule-runs ", runner)
def test_scenarios_run_with_fact_injection_off(self):
# A role that reads a bare ansible_<fact> must fail its scenario here (#364), whichever way the pins went.
for fail in ("", "1"):
with self.subTest(pins_differ=bool(fail)):
self.log.write_text("")
result = self.run_script(STUB_FAIL_sha256sum=fail)
self.assertEqual(result.returncode, 0, result.stderr)
(runner,) = self.calls("runner")
self.assertIn(" inject=False ", runner)
def test_changed_pins_are_installed_and_put_first(self):
result = self.run_script(STUB_FAIL_sha256sum="1")
self.assertEqual(result.returncode, 0, result.stderr)