Skip to content

Conversation

@richm
Copy link
Contributor

@richm richm commented Jan 6, 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 Ansible playbooks, test inventories, and documentation to use fact data via ansible_facts instead of legacy fact variables, aligning with newer Ansible INJECT_FACTS_AS_VARS=false behavior.

Enhancements:

  • Replace deprecated direct fact variables and ansible_env usages in test playbooks with ansible_facts-based lookups.
  • Adjust generated test inventory to populate legacy fact-style keys from ansible_facts while keeping connection variables unchanged.
  • Clarify README-ostree documentation to reference ansible_facts keys for distribution information instead of deprecated variables.
  • Update internal distro helper variables to rely on ansible_facts['distribution'] for Red Hat and Fedora detection.
  • Refresh changelog entry to note use of ansible_facts["os_family"] in templates.

…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>
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 6, 2026

Reviewer's Guide

Refactors Ansible playbooks, tests, templates, and docs to stop using injected fact variables (e.g., ansible_distribution, ansible_env, ansible_all_ipv4_addresses) and instead consistently access facts via ansible_facts, including adjusting inventory generation and documentation accordingly.

File-Level Changes

Change Details Files
Replace deprecated direct fact variables with ansible_facts-based lookups in SSH-related test playbooks.
  • Compute kdump_test_ssh_source from ansible_facts['env']['SSH_CONNECTION'] instead of ansible_env.
  • Use hostvars[...] ansible_facts keys (all_ipv4_addresses, all_ipv6_addresses, default_ipv4) instead of ansible_all_* and ansible_default_ipv4.
  • Read user id from hostvars[...] ansible_facts['user_id'] instead of ansible_user_id.
  • Update EL6 skip conditionals to check ansible_facts['distribution'] and ansible_facts['distribution_major_version'] instead of ansible_distribution*.
tests/tests_ssh.yml
tests/tests_ssh_reboot.yml
Adjust dynamic inventory template to reconstruct legacy-style vars from ansible_facts and clearly separate facts from connection variables.
  • Iterate over fact keys (all_ipv4_addresses, all_ipv6_addresses, default_ipv4, default_ipv6) under hostvars[inventory_hostname]['ansible_facts'] and emit legacy ansible_* variables from that mapping when present.
  • Treat connection settings (ansible_host, ansible_port, ansible_ssh_common_args, ansible_ssh_private_key_file, ansible_user) as normal hostvars instead of facts.
  • Document in-template which keys come from ansible_facts vs direct connection variables.
tests/inventory.yaml.j2
Update distro-detection helpers and documentation to reference ansible_facts instead of deprecated fact variables.
  • Change __kdump_is_rh_distro and __kdump_is_rh_distro_fedora helpers to compare against ansible_facts['distribution'] instead of ansible_distribution in both test vars and role vars.
  • Update README-ostree.md to describe DISTRO-VERSION in terms of ansible_facts['distribution'] and ansible_facts['distribution_version'].
  • Adjust CHANGELOG entry to say ansible_facts["os_family"] is used in templates rather than ansible_os_family.
tests/vars/rh_distros_vars.yml
vars/main.yml
README-ostree.md
CHANGELOG.md

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

@richm
Copy link
Contributor Author

richm commented Jan 6, 2026

[citest]

Copy link
Contributor

@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:

  • Several places index directly into ansible_facts/ansible_facts['env'] (e.g. ansible_facts['env']['SSH_CONNECTION'], ansible_facts['default_ipv4']) which will raise errors if those keys are absent; consider using default(), get(), or |d({}) patterns in Jinja to make these references more robust.
  • In tests/inventory.yaml.j2, you now materialize the legacy ansible_* variables from ansible_facts, but only for IP-related keys; if other legacy facts are still used elsewhere, it may be worth centralizing all such mappings here to avoid subtle inconsistencies between hosts.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Several places index directly into `ansible_facts`/`ansible_facts['env']` (e.g. `ansible_facts['env']['SSH_CONNECTION']`, `ansible_facts['default_ipv4']`) which will raise errors if those keys are absent; consider using `default()`, `get()`, or `|d({})` patterns in Jinja to make these references more robust.
- In `tests/inventory.yaml.j2`, you now materialize the legacy `ansible_*` variables from `ansible_facts`, but only for IP-related keys; if other legacy facts are still used elsewhere, it may be worth centralizing all such mappings here to avoid subtle inconsistencies between hosts.

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 richm merged commit a1d6274 into linux-system-roles:main Jan 7, 2026
29 checks passed
@richm richm deleted the inject-facts-as-vars branch January 7, 2026 14:39
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