fix: read facts through ansible_facts and run Molecule with fact injection off #405

Open
Dragonish wants to merge 3 commits from fix/364-ansible-facts into main
pull from: fix/364-ansible-facts
Collaborator

What and why

Closes #364

ansible-core deprecates injecting facts as top-level variables (removal is scheduled for 2.24, see #364). Three roles still read a bare fact, which is undefined when inject_facts_as_vars is false:

  • system_baseline: tasks/reboot.yml read ansible_os_family. With injection off the task fails with 'ansible_os_family' is undefined. The reboot entry point is affected too, since it is that file.
  • docker: tasks/install.yml read ansible_distribution_release for the APT source line.
  • gitea_runner: tasks/main.yml read ansible_date_time for the forced re-registration backup name.

They now read ansible_facts['os_family'], ansible_facts['distribution_release'] and ansible_facts['date_time']['iso8601_basic_short']. The argument specs and READMEs that name the facts follow. The rendered source line and backup name are unchanged.

scripts/run_molecule_in_ci_image.sh now exports ANSIBLE_INJECT_FACT_VARS=False before it runs the scenarios, so a role that reads an injected fact fails its scenario. tests/scripts/test_run_molecule_in_ci_image.py asserts the export for both pin branches. The script is not on the selector's IGNORED list, so this pull request runs every scenario, which is the point.

The sweep covered every ansible_* token in roles/, extensions/, scripts/, tests/ and .gitea/ (including molecule prepare, converge and verify); what is left is magic variables (ansible_check_mode, ansible_failed_result, ansible_collections, connection variables) and ansible_facts[...].

Verified

  • python3 -m unittest discover -s tests/scripts -p 'test_run_molecule_in_ci_image.py': 7 tests pass. The new test fails (inject=unset) when the export line is removed.
  • All commit-stage hooks passed locally (ansible-lint, changelog fragments lint, REUSE, Conventional Commit, Assisted-by).
  • On localhost with ansible-core 2.22.0 and ANSIBLE_INJECT_FACT_VARS=False, the system_baseline reboot entry point (include_role with tasks_from: reboot, --check) fails on origin/main with 'ansible_os_family' is undefined and passes with this change.
  • With the same setting, ansible_facts['distribution_release'] and ansible_facts['date_time']['iso8601_basic_short'] render, and the old ansible_distribution_release and ansible_date_time are undefined.
  • An independent read-only review of the diff found nothing to change before the push (nits applied: the 2.24 claim is attributed, the trailer names the model).

Not verified

  • The Molecule scenarios with injection off: Molecule runs only in CI, so this pull request's own run is the first proof. If a scenario fails in create or prepare because the driver or a collection reads an injected fact, the fix is to scope the setting to the role plays (provisioner.env) instead of dropping it.
  • The docker and gitea_runner task changes end to end (only the expressions were rendered, not the tasks run on a host).
  • ansible-test sanity runs in the pre-push hook and in CI; I have not seen its result yet.

  • I confirm third-party material is recorded in NOTICE and REUSE.toml, or there is none. (None.)

Assisted-by: Claude Code:claude-sonnet-5-5

## What and why Closes #364 ansible-core deprecates injecting facts as top-level variables (removal is scheduled for 2.24, see #364). Three roles still read a bare fact, which is undefined when `inject_facts_as_vars` is false: - `system_baseline`: `tasks/reboot.yml` read `ansible_os_family`. With injection off the task fails with `'ansible_os_family' is undefined`. The `reboot` entry point is affected too, since it is that file. - `docker`: `tasks/install.yml` read `ansible_distribution_release` for the APT source line. - `gitea_runner`: `tasks/main.yml` read `ansible_date_time` for the forced re-registration backup name. They now read `ansible_facts['os_family']`, `ansible_facts['distribution_release']` and `ansible_facts['date_time']['iso8601_basic_short']`. The argument specs and READMEs that name the facts follow. The rendered source line and backup name are unchanged. `scripts/run_molecule_in_ci_image.sh` now exports `ANSIBLE_INJECT_FACT_VARS=False` before it runs the scenarios, so a role that reads an injected fact fails its scenario. `tests/scripts/test_run_molecule_in_ci_image.py` asserts the export for both pin branches. The script is not on the selector's IGNORED list, so this pull request runs every scenario, which is the point. The sweep covered every `ansible_*` token in `roles/`, `extensions/`, `scripts/`, `tests/` and `.gitea/` (including molecule `prepare`, `converge` and `verify`); what is left is magic variables (`ansible_check_mode`, `ansible_failed_result`, `ansible_collections`, connection variables) and `ansible_facts[...]`. ## Verified - `python3 -m unittest discover -s tests/scripts -p 'test_run_molecule_in_ci_image.py'`: 7 tests pass. The new test fails (`inject=unset`) when the `export` line is removed. - All commit-stage hooks passed locally (ansible-lint, changelog fragments lint, REUSE, Conventional Commit, `Assisted-by`). - On localhost with ansible-core 2.22.0 and `ANSIBLE_INJECT_FACT_VARS=False`, the `system_baseline` `reboot` entry point (`include_role` with `tasks_from: reboot`, `--check`) fails on `origin/main` with `'ansible_os_family' is undefined` and passes with this change. - With the same setting, `ansible_facts['distribution_release']` and `ansible_facts['date_time']['iso8601_basic_short']` render, and the old `ansible_distribution_release` and `ansible_date_time` are undefined. - An independent read-only review of the diff found nothing to change before the push (nits applied: the 2.24 claim is attributed, the trailer names the model). ## Not verified - The Molecule scenarios with injection off: Molecule runs only in CI, so this pull request's own run is the first proof. If a scenario fails in `create` or `prepare` because the driver or a collection reads an injected fact, the fix is to scope the setting to the role plays (`provisioner.env`) instead of dropping it. - The `docker` and `gitea_runner` task changes end to end (only the expressions were rendered, not the tasks run on a host). - `ansible-test sanity` runs in the pre-push hook and in CI; I have not seen its result yet. --- - [x] I confirm third-party material is recorded in `NOTICE` and `REUSE.toml`, or there is none. (None.) Assisted-by: Claude Code:claude-sonnet-5-5
Dragonish added 1 commit 2026-11-26 21:35:24 +00:00
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
26b6e37a09
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
CODEOWNERS rules requested review from Defame1297 2026-11-26 21:35:24 +00:00
Dragonish scheduled this pull request to auto merge when all checks succeed 2026-11-26 21:38:40 +00:00
Owner

@Dragonish Nice!

@Dragonish Nice!
Defame1297 approved these changes 2026-11-26 21:44:08 +00:00
Dismissed
Defame1297 added 1 commit 2026-11-26 21:44:18 +00:00
Merge branch 'main' into fix/364-ansible-facts
Build / build (pull_request) Successful in 29s
Lint / lint (pull_request) Successful in 2m10s
Molecule / molecule (pull_request) Canceled after 5m20s
d1b4501c2b
Defame1297 added 1 commit 2026-11-26 21:51:01 +00:00
Merge branch 'main' into fix/364-ansible-facts
Build / build (pull_request) Successful in 29s
Molecule / molecule (pull_request) In progress
Lint / lint (pull_request) Successful in 2m56s
464cc5848b
Defame1297 approved these changes 2026-11-26 21:51:17 +00:00
Some checks are pending
Build / build (pull_request) Successful in 29s
Required
Details
Molecule / molecule (pull_request) In progress
Required
Details
Lint / lint (pull_request) Successful in 2m56s
Required
Details
Some required checks are missing.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin fix/364-ansible-facts:fix/364-ansible-facts
git checkout fix/364-ansible-facts
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#405