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
merge into: Mortis:main
Mortis:main
Mortis:chore/release-3.1.0
Labels
Clear labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Breaking change that won't be backward compatible
Something is not working
Documentation changes
Improve existing functionality
New functionality
This is security issue
Issue or pull request related to testing
Priority
Critical
1
The priority is critical
Priority
High
2
The priority is high
Priority
Medium
3
The priority is medium
Priority
Low
4
The priority is low
Reviewed
Confirmed
1
Issue has been confirmed
Reviewed
Duplicate
2
This issue or pull request already exists
Reviewed
Invalid
3
Invalid issue
Reviewed
Won't Fix
3
This issue won't be fixed
Status
Blocked
1
Something is blocking this issue or pull request
Status
Need More Info
2
Feedback is required to reproduce issue or to continue work
Status
Abandoned
3
Somebody has started to work on this but abandoned work
Status
Needs Triage
Maintainer needs to evaluate this issue
Status
Ready for Agent
Fully specified, ready for an AFK agent
Status
Ready for Human
Requires human implementation
Wayfinder
Grilling
Decision ticket resolved in conversation with the maintainer
Wayfinder
Map
Wayfinder map: index of a planning effort and its decision tickets
Wayfinder
Prototype
Decision ticket resolved by reacting to a rough concrete artifact
Wayfinder
Research
Decision ticket resolved by reading outside sources
Wayfinder
Task
Manual work that must happen before a decision can be made
No labels
Milestone
No items
No Milestone
Projects
Clear projects
No projects
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: Mortis/Kamino#405
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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_varsis false:system_baseline:tasks/reboot.ymlreadansible_os_family. With injection off the task fails with'ansible_os_family' is undefined. Therebootentry point is affected too, since it is that file.docker:tasks/install.ymlreadansible_distribution_releasefor the APT source line.gitea_runner:tasks/main.ymlreadansible_date_timefor the forced re-registration backup name.They now read
ansible_facts['os_family'],ansible_facts['distribution_release']andansible_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.shnow exportsANSIBLE_INJECT_FACT_VARS=Falsebefore it runs the scenarios, so a role that reads an injected fact fails its scenario.tests/scripts/test_run_molecule_in_ci_image.pyasserts 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 inroles/,extensions/,scripts/,tests/and.gitea/(including moleculeprepare,convergeandverify); what is left is magic variables (ansible_check_mode,ansible_failed_result,ansible_collections, connection variables) andansible_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 theexportline is removed.Assisted-by).ANSIBLE_INJECT_FACT_VARS=False, thesystem_baselinerebootentry point (include_rolewithtasks_from: reboot,--check) fails onorigin/mainwith'ansible_os_family' is undefinedand passes with this change.ansible_facts['distribution_release']andansible_facts['date_time']['iso8601_basic_short']render, and the oldansible_distribution_releaseandansible_date_timeare undefined.Not verified
createorpreparebecause 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.dockerandgitea_runnertask changes end to end (only the expressions were rendered, not the tasks run on a host).ansible-test sanityruns in the pre-push hook and in CI; I have not seen its result yet.NOTICEandREUSE.toml, or there is none. (None.)Assisted-by: Claude Code:claude-sonnet-5-5
@Dragonish Nice!
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.