Skip to content

Conversation

@richm
Copy link
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 variables, tasks, and tests to use the ansible_facts dictionary instead of legacy fact variables for compatibility with newer Ansible versions.

Enhancements:

  • Replace direct fact variables (e.g., ansible_distribution, ansible_pkg_mgr, ansible_lvm, ansible_python, ansible_devices, ansible_architecture) with ansible_facts lookups across role vars and tasks.
  • Extend required facts to include the package manager fact to support the new access pattern.

Tests:

  • Update test playbooks and helper vars to reference facts via ansible_facts, aligning tests with the new fact access pattern and avoiding deprecation warnings.

…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 5, 2026

Reviewer's Guide

Refactors the role and its tests to stop using deprecated top-level Ansible fact variables and instead consistently access facts via the ansible_facts dictionary so it works with INJECT_FACTS_AS_VARS=false, while also ensuring required facts (including pkg_mgr) are gathered.

File-Level Changes

Change Details Files
Replace all uses of deprecated top-level fact variables with ansible_facts lookups and align supporting variables with the new access pattern.
  • Update documentation comments in tests to reference ansible_facts keys instead of top-level fact variables for distribution and OS family.
  • Add pkg_mgr to the list of required facts so package manager information is available when using ansible_facts.
  • Update Red Hat distribution helper variables to test ansible_facts['distribution'] membership instead of ansible_distribution.
  • Change COPR enablement tasks to use ansible_facts['pkg_mgr'] instead of ansible_pkg_mgr when invoking repo and copr commands.
  • Adjust LVM-related tests to access LVM facts via ansible_facts['lvm'] rather than ansible_lvm.
  • Adjust tests that depend on distribution or major version to use ansible_facts['distribution'] and ansible_facts['distribution_major_version'].
  • Update tests to access device facts via ansible_facts['devices'] instead of ansible_devices.
  • Update Python interpreter references to use ansible_facts['python'].executable instead of ansible_python.executable.
  • Update architecture-based package selection in vars files to use ansible_facts['architecture'] instead of ansible_architecture.
tests/tests_include_vars_from_parent.yml
vars/main.yml
tasks/enable_copr.yml
tests/test-verify-pool-members.yml
tests/tests_change_disk_fs.yml
tests/tests_change_fs.yml
tests/tests_change_fs_use_partitions.yml
tests/tests_create_thinp_then_remove.yml
tests/vars/rh_distros_vars.yml
tests/test-verify-volume-size.yml
tests/tests_create_lv_size_equal_to_vg.yml
tests/tests_lvm_errors.yml
tests/tests_misc.yml
tests/tests_resize.yml
tests/verify-pool-stratis.yml
vars/Fedora.yml
vars/OracleLinux_9.yml
vars/RedHat_10.yml
vars/RedHat_7.yml
vars/RedHat_8.yml
vars/RedHat_9.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 5, 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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `vars/main.yml:9` </location>
<code_context>
   - distribution_major_version
   - distribution_version
   - os_family
+  - pkg_mgr

 # the subsets of ansible_facts that need to be gathered in case any of the
</code_context>

<issue_to_address>
**issue:** Architecture fact is now used via ansible_facts but isn’t listed in required facts, which could lead to missing data when gathering a minimal fact subset.

`pkg_mgr` was correctly added to `__storage_required_facts` now that it’s accessed via `ansible_facts['pkg_mgr']`. Similarly, several distro var files now use `ansible_facts['architecture']`, but `architecture` is not in `__storage_required_facts`. If facts are gathered with a minimal subset, `architecture` may be missing at runtime, so it should likely be added here as well.
</issue_to_address>

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.

@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 10.34%. Comparing base (59fd1c6) to head (21261a6).
⚠️ Report is 101 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (59fd1c6) and HEAD (21261a6). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (59fd1c6) HEAD (21261a6)
sanity 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #577      +/-   ##
==========================================
- Coverage   16.54%   10.34%   -6.21%     
==========================================
  Files           2        8       +6     
  Lines         284     2020    +1736     
  Branches       79        0      -79     
==========================================
+ Hits           47      209     +162     
- Misses        237     1811    +1574     
Flag Coverage Δ
sanity ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@richm richm merged commit 7b42c32 into linux-system-roles:main Jan 6, 2026
37 of 40 checks passed
@richm richm deleted the inject-facts-as-vars branch January 6, 2026 14:48
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.

2 participants