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

Enhancements:

  • Replace direct Ansible fact variables with ansible_facts lookups in tasks, vars, and test playbooks to support INJECT_FACTS_AS_VARS=false.

…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

sourcery-ai bot commented Jan 6, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors Ansible role and test logic to stop using deprecated top-level fact variables (e.g., ansible_distribution, ansible_python_version) and instead consistently reference ansible_facts, ensuring compatibility with INJECT_FACTS_AS_VARS=false in newer Ansible versions.

Flow diagram for version specific variable file selection using ansible_facts

flowchart TD
  Start["Start role execution"] --> CheckFacts["Access ansible_facts"]
  CheckFacts --> BuildList["Build with_first_found list using
ansible_facts['distribution'],
ansible_facts['distribution_version'],
ansible_facts['distribution_major_version'],
ansible_facts['os_family']"]

  BuildList --> Option1["Try file
<distribution>-<distribution_version>.yml"]
  Option1 --> Found1{File exists?}
  Found1 -->|Yes| Use1["include_vars for
<distribution>-<distribution_version>.yml"]
  Found1 -->|No| Option2

  Option2["Try file
<distribution>-<distribution_major_version>.yml"] --> Found2{File exists?}
  Found2 -->|Yes| Use2["include_vars for
<distribution>-<distribution_major_version>.yml"]
  Found2 -->|No| Option3

  Option3["Try file
<distribution>.yml"] --> Found3{File exists?}
  Found3 -->|Yes| Use3["include_vars for
<distribution>.yml"]
  Found3 -->|No| Option4

  Option4["Try file
<os_family>.yml"] --> Found4{File exists?}
  Found4 -->|Yes| Use4["include_vars for
<os_family>.yml"]
  Found4 -->|No| DefaultOpt

  DefaultOpt["Fall back to default.yml"] --> End["Variables loaded"]
Loading

File-Level Changes

Change Details Files
Replace direct use of top-level Ansible fact variables with lookups via ansible_facts for conditionals, path selection, and helper vars.
  • Update SELinux tool installation test tasks to check python version and distribution via ansible_facts keys in when conditions.
  • Adjust variable file selection logic to build filenames using distribution, distribution_version, distribution_major_version, and os_family from ansible_facts.
  • Update main role tasks to gate RHEL-specific logic and choose setup task files based on distribution, distribution_major_version, and pkg_mgr from ansible_facts.
  • Change helper variables that classify Red Hat-family distributions in vars and test vars to use ansible_facts-based distribution checks.
tests/tasks/install_selinux_tools.yml
tasks/set_vars.yml
tasks/main.yml
tests/vars/rh_distros_vars.yml
vars/main.yml

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

@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 reviewed your changes and they look great!


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 ecf30a1 into linux-system-roles:main Jan 7, 2026
28 of 31 checks passed
@richm richm deleted the inject-facts-as-vars branch January 7, 2026 14:33
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