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.

Set the bootloader_facts variable separately since it will not be set
automatically.

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 ansible_facts instead of injected fact variables and ensure bootloader_facts is explicitly set when gathering facts.

Bug Fixes:

  • Ensure bootloader_facts is available as a variable when INJECT_FACTS_AS_VARS is disabled.

Enhancements:

  • Replace deprecated fact variable usage with ansible_facts lookups across role variables, tasks, and tests to be compatible with newer Ansible versions.

Tests:

  • Adjust test playbooks and vars to rely on ansible_facts rather than deprecated fact variables for distribution and architecture checks.

…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.

Set the bootloader_facts variable separately since it will not be set
automatically.

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 spetrosi as a code owner January 5, 2026 19:36
@richm
Copy link
Contributor Author

richm commented Jan 5, 2026

[citest]

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 5, 2026

Reviewer's Guide

Refactors the role and its tests to stop relying on auto-injected Ansible fact variables and instead use the ansible_facts dictionary explicitly, and adds an explicit set_fact workaround so bootloader_facts remains available when INJECT_FACTS_AS_VARS is false.

Sequence diagram for bootloader_facts collection and workaround

sequenceDiagram
    actor User
    participant AnsibleController
    participant RoleTasksMain as Role_tasks_main_yml
    participant BootloaderFactsModule as bootloader_facts_module

    User->>AnsibleController: Run_play_with_role
    AnsibleController->>RoleTasksMain: Execute_tasks

    alt bootloader_gather_facts_is_true
        RoleTasksMain->>BootloaderFactsModule: bootloader_facts
        BootloaderFactsModule-->>RoleTasksMain: ansible_facts.bootloader_facts

        RoleTasksMain->>RoleTasksMain: set_fact bootloader_facts
        Note over RoleTasksMain: bootloader_facts := ansible_facts['bootloader_facts']
    else bootloader_gather_facts_is_false
        RoleTasksMain->>RoleTasksMain: Skip_fact_collection_and_set_fact
    end

    RoleTasksMain-->>AnsibleController: Role_completed
    AnsibleController-->>User: Report_status
Loading

Flow diagram for using ansible_facts and setting bootloader_facts

flowchart TD
    Start["Start role execution"] --> CheckArch["Check architecture: ansible_facts['architecture'] == 's390x'?"]
    CheckArch -->|Yes| SkipRole["Fail role for unsupported s390x"]
    CheckArch -->|No| ContinueRole["Continue role tasks"]

    ContinueRole --> CheckGather["bootloader_gather_facts | bool?"]
    CheckGather -->|False| EndNoFacts["Skip bootloader facts collection"]

    CheckGather -->|True| CollectFacts["Run bootloader_facts module"]
    CollectFacts --> StoreFacts["ansible_facts['bootloader_facts'] available"]
    StoreFacts --> SetFactWorkaround["set_fact bootloader_facts := ansible_facts['bootloader_facts']"]
    SetFactWorkaround --> EndWithFacts["bootloader_facts variable available even when INJECT_FACTS_AS_VARS=false"]

    EndNoFacts --> End["End role"]
    EndWithFacts --> End
Loading

File-Level Changes

Change Details Files
Replace deprecated direct fact variables with ansible_facts lookups throughout role variables, tasks, and tests.
  • Update comments in test playbook to reference ansible_facts keys instead of legacy top-level fact variables.
  • Change distro and OS-family based paths and conditionals in role vars to use ansible_facts['distribution'] and ansible_facts['os_family'].
  • Adjust Red Hat/Fedora detection variables in both role vars and test vars to use ansible_facts['distribution'].
  • Update s390x architecture checks in role tasks and tests to use ansible_facts['architecture'] rather than ansible_architecture.
tests/tests_include_vars_from_parent.yml
vars/main.yml
tests/vars/rh_distros_vars.yml
tests/tasks/skip_on_s390x.yml
tasks/main.yml
Ensure bootloader_facts is available as a variable when fact injection is disabled.
  • Keep collecting bootloader facts via the bootloader_facts module when bootloader_gather_facts is true.
  • Add a set_fact task that copies ansible_facts['bootloader_facts'] into a bootloader_facts variable, guarded by the same condition.
tasks/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

@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.90%. Comparing base (63d7c0c) to head (90f10f1).
⚠️ Report is 89 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #180      +/-   ##
==========================================
+ Coverage   78.43%   86.90%   +8.47%     
==========================================
  Files           2        2              
  Lines         255      275      +20     
==========================================
+ Hits          200      239      +39     
+ Misses         55       36      -19     
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.

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 left some high level feedback:

  • For the new Set bootloader_facts variable task, consider guarding against missing ansible_facts['bootloader_facts'] (e.g. bootloader_facts: "{{ ansible_facts['bootloader_facts'] | default({}) }}") in case the bootloader_facts module is unavailable or fails to populate facts.
  • In places where you now use ansible_facts['architecture'] in when conditions, double-check whether facts are always guaranteed to be gathered for these tasks; if not, mirroring the defensive check used in skip_on_s390x.yml (verifying the key exists) would avoid undefined-variable issues.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- For the new `Set bootloader_facts variable` task, consider guarding against missing `ansible_facts['bootloader_facts']` (e.g. `bootloader_facts: "{{ ansible_facts['bootloader_facts'] | default({}) }}"`) in case the `bootloader_facts` module is unavailable or fails to populate facts.
- In places where you now use `ansible_facts['architecture']` in `when` conditions, double-check whether facts are always guaranteed to be gathered for these tasks; if not, mirroring the defensive check used in `skip_on_s390x.yml` (verifying the key exists) would avoid undefined-variable issues.

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 5c93e5a into linux-system-roles:main Jan 7, 2026
39 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.

2 participants