Use ansible_facts[] instead of injected top-level facts - #187
Merged
Conversation
The uv.lock refresh in this branch bumps ansible-core 2.20.4 -> 2.21.2,
which tags every top-level injected fact with a deprecation warning:
[DEPRECATION WARNING] INJECT_FACTS_AS_VARS default to `True` is deprecated
Injection is removed outright in ansible-core 2.24, at which point all 189
bare references in this repo would silently resolve to undefined and break
every build. Migrate now rather than discover it at deploy time.
Rewrites 189 references across 69 files to the ansible_facts['name'] form:
ansible_env (89), ansible_processor_vcpus (63), ansible_processor_count (5)
and ansible_architecture (1). Includes the two .def templates that neither
linter parses, and the commented-out occurrences that would otherwise stay
around as copy-paste sources. Magic and connection vars (ansible_run_tags,
ansible_connection, ansible_python_interpreter) are not facts and are
untouched.
ansible-lint 26.6.0 ships no rule covering this (deprecated-bare-vars is
unrelated - it targets bare with_items values), so enforcement is added by
hand in two places:
- ansible.cfg sets inject_facts_as_vars = False, so any missed reference
fails loudly at runtime instead of resolving to the wrong value
- a grep step in the lint workflow gates reintroduction at PR time, and
covers the .def/.sh/.lua/.j2 templates neither linter looks at
add-software/SKILL.md documented the deprecated form and would have kept
reintroducing it in every new package; CLAUDE.md gains the convention.
Verified: yamllint and ansible-lint both clean (production profile); a live
playbook run confirms all four facts resolve, both ansible_env shapes work
(attribute access and `in` guard), the environment: keyword templates
correctly (MAKEFLAGS=-j 10, PATH prepend intact), zero deprecation warnings
are emitted, and `ansible_processor_vcpus is defined` is now false.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SVQzRA7FchcYjuJRMrCL93
Collaborator
Author
|
@MikeCTZA Nothing to see in this one. |
MikeCTZA
approved these changes
Jul 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The
uv lock --upgradein this branch bumps ansible-core 2.20.4 → 2.21.2, which tags every top-level injected fact with a deprecation warning:The setting itself isn't marked deprecated in
config/base.yml— the warning comes fromansible/vars/manager.py:51-56at templating time, which is why it only surfaced after the upgrade.Injection is removed in ansible-core 2.24. At that point all 189 bare references here silently resolve to undefined and every build breaks. Better to migrate now than find out mid-deploy.
What changed
189 references across 69 files →
ansible_facts['name']:ansible_envansible_processor_vcpusansible_processor_countansible_architectureIncludes the two
.deftemplates (RStudio.def,bcbio.def) that neither linter parses, and the ~30 commented-out occurrences — those are the copy-paste source for new task files.Magic and connection vars (
ansible_run_tags,ansible_connection,ansible_python_interpreter) are not facts and are untouched.Enforcement
ansible-lint 26.6.0 has no rule for this — I checked all 52;
deprecated-bare-varsis unrelated (it targets barewith_itemsvalues), and nothing in ourskip_listwas hiding it. So the fix carries its own guard:ansible.cfg:inject_facts_as_vars = False— a missed reference now fails loudly at runtime instead of resolving to the wrong value. Revertible by one line..github/workflows/lint.yml: grep step gating reintroduction at PR time, covering the.def/.sh/.lua/.j2templates neither linter looks at.add-software/SKILL.mddocumented the deprecated form and would have reintroduced it in every new package. Fixed, plus aCLAUDE.mdconvention bullet.Verification
yamllint→ clean;ansible-lint→0 failure(s), 0 warning(s) in 439 files, production profile passedansible_envshapes work (attribute access andinguard, hit and miss); zero deprecation warnings;ansible_processor_vcpus is definedis now false, confirming injection is genuinely off rather than just quietenvironment:keyword (whichdebugwouldn't exercise):MAKEFLAGS=[-j 10], PATH prepend intactNot done: a full compile of a real package. The inventory is
localand deploys are manual, so I didn't want to build software on a live host unprompted. Theenvironment:test covers the templating gap; worth one real build before merging if you want belt-and-braces.Also in this PR
uv.lock(ansible 13.5.0 → 14.2.0, ansible-core 2.20.4 → 2.21.2, ansible-lint 26.3.0 → 26.6.0) — it's the reason for the change, so it belongs here.Follow-up, not this PR
.ansible-lintskipsmeta-no-info, which no longer appears inansible-lint -Lafter the version bump — likely inert now, worth pruning separately.🤖 Generated with Claude Code
https://claude.ai/code/session_01SVQzRA7FchcYjuJRMrCL93