fix: read facts through ansible_facts before ansible-core 2.24 stops injecting them as variables #364

Open
opened 2026-11-25 08:32:43 +00:00 by Claude · 0 comments
Owner

Problem

ansible-core 2.22 warns at runtime:

[DEPRECATION WARNING]: INJECT_FACTS_AS_VARS default to True is deprecated, top-level facts will not be auto injected after the change. This feature will be removed from ansible-core version 2.24.
Origin: …/mortis/kamino/roles/system_baseline/tasks/reboot.yml:7:9

When the default flips, bare top-level facts are undefined. Any consumer running with inject_facts_as_vars = False already sees that today.

Known uses on main

  • roles/system_baseline/tasks/reboot.yml:7: ansible_os_family. This one is in the reboot entry point, which consumers call directly.
  • roles/docker/tasks/install.yml:33: ansible_distribution_release in the APT source line.
  • The argument specs and READMEs of both roles name these facts.

A full sweep is needed, because the grep above only checked common names: every ansible_<fact> outside ansible_facts[...] in roles/, plus the molecule scenarios.

Fix

  • Use ansible_facts['os_family'], ansible_facts['distribution_release'] and so on, and update the argument specs and READMEs.
  • Add inject_facts_as_vars = False to the Collection's test config (molecule ansible.cfg / ANSIBLE_INJECT_FACT_VARS=False), so a regression fails in CI.
  • Changelog fragment (bugfix). Behaviour is unchanged for consumers.

Acceptance

  • No INJECT_FACTS_AS_VARS deprecation warning from any role in the Molecule runs.
  • The Molecule scenarios pass with fact injection off.

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

## Problem ansible-core 2.22 warns at runtime: > [DEPRECATION WARNING]: INJECT_FACTS_AS_VARS default to `True` is deprecated, top-level facts will not be auto injected after the change. This feature will be removed from ansible-core version 2.24. > Origin: …/mortis/kamino/roles/system_baseline/tasks/reboot.yml:7:9 When the default flips, bare top-level facts are undefined. Any consumer running with `inject_facts_as_vars = False` already sees that today. ## Known uses on main - `roles/system_baseline/tasks/reboot.yml:7`: `ansible_os_family`. This one is in the `reboot` entry point, which consumers call directly. - `roles/docker/tasks/install.yml:33`: `ansible_distribution_release` in the APT source line. - The argument specs and READMEs of both roles name these facts. A full sweep is needed, because the grep above only checked common names: every `ansible_<fact>` outside `ansible_facts[...]` in `roles/`, plus the molecule scenarios. ## Fix - Use `ansible_facts['os_family']`, `ansible_facts['distribution_release']` and so on, and update the argument specs and READMEs. - Add `inject_facts_as_vars = False` to the Collection's test config (molecule `ansible.cfg` / `ANSIBLE_INJECT_FACT_VARS=False`), so a regression fails in CI. - Changelog fragment (bugfix). Behaviour is unchanged for consumers. ## Acceptance - No `INJECT_FACTS_AS_VARS` deprecation warning from any role in the Molecule runs. - The Molecule scenarios pass with fact injection off. Assisted-by: Claude Code:claude-opus-5-5
Dragonish added the
Status
Ready for Agent
label 2026-11-26 21:11:34 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#364