Skip to content

Conversation

@richm
Copy link
Contributor

@richm richm commented Jan 7, 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 use of ansible_distribution* variables with ansible_facts lookups across role logic and supporting test playbooks to align with Ansible 2.20+ deprecations.

…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 requested a review from ptoscano as a code owner January 7, 2026 23:15
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 7, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors all use of top-level Ansible fact variables to the supported ansible_facts[...] lookups so the role and its tests work with INJECT_FACTS_AS_VARS=false and upcoming Ansible 2.24 changes.

Flow diagram for insights registration and unregistration using ansible_facts

flowchart TD
  start["Start role execution with gathered ansible_facts"]

  start --> distro_check{"ansible_facts['distribution'] == RedHat"}

  distro_check -->|No| end_no_rh["Skip insights registration and unregistration tasks"]
  distro_check -->|Yes| state_check_unreg{"rhc_insights.state or rhc_state indicate unregistration"}

  state_check_unreg -->|Yes| do_unreg["Include task file insights-client-unregistration.yml"]
  state_check_unreg -->|No| state_check_reg{"rhc_insights.state and rhc_state indicate registration"}

  state_check_reg -->|Yes| do_reg["Include task file insights-client.yml"]
  state_check_reg -->|No| no_action["No registration or unregistration actions"]

  do_unreg --> end_node["End role execution"]
  do_reg --> end_node
  no_action --> end_node
  end_no_rh --> end_node
Loading

Flow diagram for distro-specific vars and remediation config using ansible_facts

flowchart TD
  start["Start variable evaluation"] --> major_ver_check{"ansible_facts['distribution_major_version'] >= 10"}

  major_ver_check -->|Yes| set_ygg["Set __rhc_yggdrasil_systemd_service = 'yggdrasil'"]
  major_ver_check -->|No| set_rhcd["Set __rhc_yggdrasil_systemd_service = 'rhcd'"]

  set_ygg --> distro_check{"ansible_facts['distribution'] in __rhc_rh_distros"}
  set_rhcd --> distro_check

  distro_check -->|Yes| mark_rh["Set __rhc_is_rh_distro = true"]
  distro_check -->|No| mark_not_rh["Set __rhc_is_rh_distro = false"]

  distro_fedora_check{"ansible_facts['distribution'] in __rhc_rh_distros_fedora"}
  mark_rh --> distro_fedora_check
  mark_not_rh --> distro_fedora_check

  distro_fedora_check -->|Yes| mark_rh_fedora["Set __rhc_is_rh_distro_fedora = true"]
  distro_fedora_check -->|No| mark_not_rh_fedora["Set __rhc_is_rh_distro_fedora = false"]

  mark_rh_fedora --> ver_check["Check remediation condition: ansible_facts['distribution_version'] >= 8.4"]
  mark_not_rh_fedora --> ver_check

  ver_check -->|Yes| cfg_remediation["Execute remediation configuration block"]
  ver_check -->|No| skip_remediation["Skip remediation configuration"]

  cfg_remediation --> end_node["End variable and remediation evaluation"]
  skip_remediation --> end_node
Loading

File-Level Changes

Change Details Files
Replace distribution-related fact variables in tasks with ansible_facts lookups to ensure compatibility with INJECT_FACTS_AS_VARS=false.
  • Update conditionals in main task file to use ansible_facts['distribution'] instead of ansible_distribution for gating registration/unregistration logic.
  • Update remediation gating in insights-client tasks to use ansible_facts['distribution_version'] instead of ansible_distribution_version.
  • Update set_vars logic that checks package facts to use ansible_facts['distribution'] for Red Hat detection.
tasks/main.yml
tasks/insights-client.yml
tasks/set_vars.yml
Refactor role vars that classify distributions to use ansible_facts values for distro detection.
  • Change RHEL major-version based service selection to use ansible_facts['distribution_major_version'].
  • Switch __rhc_is_rh_distro and __rhc_is_rh_distro_fedora helper vars to use ansible_facts['distribution'] instead of ansible_distribution.
  • Mirror the same distro helper refactor in test vars to keep tests aligned with role behavior.
vars/main.yml
tests/vars/rh_distros_vars.yml
Adjust test logic to use ansible_facts-based distribution and version checks.
  • Update tests_environments gating conditions to use ansible_facts['distribution'], ['distribution_major_version'], and ['distribution_version'].
  • Change test setup for Candlepin to use ansible_facts-based distro and major version checks when deciding to run privileged.
  • Update remediation-related tests to compare ansible_facts['distribution_version'] instead of ansible_distribution_version.
tests/tests_environments.yml
tests/tasks/setup_candlepin.yml
tests/tests_insights_remediation.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

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
Copy link
Contributor Author

richm commented Jan 7, 2026

[citest]

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