Skip to content

refactor: handle INJECT_FACTS_AS_VARS=false by using ansible_facts instead#167

Merged
richm merged 1 commit intolinux-system-roles:mainfrom
richm:inject-facts-as-vars
Jan 7, 2026
Merged

refactor: handle INJECT_FACTS_AS_VARS=false by using ansible_facts instead#167
richm merged 1 commit intolinux-system-roles:mainfrom
richm:inject-facts-as-vars

Conversation

@richm
Copy link
Copy Markdown
Contributor

@richm richm commented Jan 5, 2026

Ansible 2.20 has deprecated the use of Ansible facts as variables. For
example, ansible_distribution is now deprecated in favor of
ansible_facts["distribution"]. This is due to making the default
setting INJECT_FACTS_AS_VARS=false. For now, this will create WARNING
messages, but in Ansible 2.24 it will be an error.

See https://docs.ansible.com/projects/ansible/latest/porting_guides/porting_guide_core_2.20.html#inject-facts-as-vars

Signed-off-by: Rich Megginson rmeggins@redhat.com

Summary by Sourcery

Update role and tests to use structured ansible_facts instead of legacy fact variables to be compatible with INJECT_FACTS_AS_VARS=false and newer Ansible versions.

Enhancements:

  • Replace usage of ansible_distribution, ansible_hostname, ansible_fqdn, ansible_default_ipv4, and ansible_python with ansible_facts lookups across tasks, variables, and templates to align with Ansible 2.20+ fact handling.
  • Adjust distribution helper variables to rely on ansible_facts['distribution'] and related keys for Red Hat and Fedora detection.

Tests:

  • Update dyndns and integration tests to reference host networking and FQDN information through ansible_facts, ensuring tests remain valid when facts are not injected as top-level vars.

@richm richm requested a review from spetrosi as a code owner January 5, 2026 17:13
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Jan 5, 2026

Reviewer's Guide

Refactors the role and its tests to stop using deprecated top-level Ansible fact variables and instead consistently reference facts via the ansible_facts dictionary, ensuring compatibility with INJECT_FACTS_AS_VARS=false in Ansible 2.20+.

File-Level Changes

Change Details Files
Replace deprecated top-level Ansible fact variables with ansible_facts lookups throughout role tasks, vars, and tests.
  • Update distro/version conditionals in role tasks to use ansible_facts['distribution'] and ansible_facts['distribution_version']
  • Adjust RC4 crypto policy conditionals and helper vars to rely on ansible_facts-based distribution checks
  • Refactor hostname/FQDN-related expressions and dynamic DNS tests to use ansible_facts['hostname'], ansible_facts['fqdn'], and ansible_facts['default_ipv4']
  • Update include-vars tests’ documentation comments to reference ansible_facts keys instead of deprecated fact variables
  • Change helper vars for RH distro detection in vars and test vars to use ansible_facts['distribution']
  • Update the fake_realm.py.j2 template’s shebang to use ansible_facts['python']['executable'] instead of ansible_python.executable
tasks/main.yml
tests/tests_dyndns.yml
tests/tests_full_integration_dyndns.yml
tests/tests_include_vars_from_parent.yml
tests/vars/rh_distros_vars.yml
vars/main.yml
tests/templates/fake_realm.py.j2

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In tests/tests_dyndns.yml the new ansible_facts references inside the assert strings use nested single quotes (e.g. ansible_facts['default_ipv4']['address']), which will break YAML/Jinja parsing; switch the outer quotes to double quotes or the inner ones to double quotes to avoid quoting conflicts.
  • Similarly, in tests/tests_dyndns.yml where you compare to ansible_facts['fqdn'], adjust the quoting so the Jinja expression is not using single quotes inside a single-quoted string.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In tests/tests_dyndns.yml the new ansible_facts references inside the assert strings use nested single quotes (e.g. `ansible_facts['default_ipv4']['address']`), which will break YAML/Jinja parsing; switch the outer quotes to double quotes or the inner ones to double quotes to avoid quoting conflicts.
- Similarly, in tests/tests_dyndns.yml where you compare to `ansible_facts['fqdn']`, adjust the quoting so the Jinja expression is not using single quotes inside a single-quoted string.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@richm
Copy link
Copy Markdown
Contributor Author

richm commented Jan 5, 2026

[citest]

@richm
Copy link
Copy Markdown
Contributor Author

richm commented Jan 5, 2026

[citest_bad]

…stead

Ansible 2.20 has deprecated the use of Ansible facts as variables.  For
example, `ansible_distribution` is now deprecated in favor of
`ansible_facts["distribution"]`.  This is due to making the default
setting `INJECT_FACTS_AS_VARS=false`.  For now, this will create WARNING
messages, but in Ansible 2.24 it will be an error.

See https://docs.ansible.com/projects/ansible/latest/porting_guides/porting_guide_core_2.20.html#inject-facts-as-vars

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
@richm richm force-pushed the inject-facts-as-vars branch from 0abdf53 to 83efa05 Compare January 6, 2026 19:13
@richm richm merged commit bbf8f83 into linux-system-roles:main Jan 7, 2026
21 checks passed
@richm richm deleted the inject-facts-as-vars branch January 7, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant