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

Refactor role defaults, tasks, and test playbooks to stop using deprecated top-level Ansible fact variables and instead reference facts via the ansible_facts mapping for compatibility with INJECT_FACTS_AS_VARS=false.

Enhancements:

  • Update role logic to derive distribution, version, OS family, and Python version from ansible_facts instead of legacy fact variables.
  • Align conditional execution and templating in defaults and tasks with the new ansible_facts-based access patterns to preserve existing behavior.

Tests:

  • Refresh all network-related test playbooks and helpers to use ansible_facts-based conditionals for distro and version checks, keeping the suite compatible with newer Ansible versions.

Chores:

  • Clean up internal variables that detect Red Hat and Fedora distributions to rely on ansible_facts for fact access.

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

Reviewer's Guide

Refactors the role and its test suite to stop using deprecated top-level Ansible fact variables (e.g. ansible_distribution, ansible_distribution_major_version, ansible_os_family, ansible_python) and instead reference the corresponding keys under ansible_facts, keeping all existing logic and conditionals intact while making the code compatible with INJECT_FACTS_AS_VARS=false in newer Ansible versions.

Flow diagram for network provider selection based on ansible_facts

flowchart TD
  A[Start] --> B[Read ansible_facts_distribution]
  B --> C[Read ansible_facts_distribution_major_version]
  C --> D{ansible_facts_distribution in __network_rh_distros?}
  D -- No --> G[Set network_provider_os_default to nm]
  D -- Yes --> E{ansible_facts_distribution_major_version &lt; 7?}
  E -- Yes --> F[Set network_provider_os_default to initscripts]
  E -- No --> G[Set network_provider_os_default to nm]
  F --> H[End]
  G --> H[End]
Loading

File-Level Changes

Change Details Files
Replace deprecated top-level fact variables with ansible_facts lookups across role tasks and defaults while preserving conditional logic and behavior.
  • Update all when: conditions in tasks/main.yml to use ansible_facts['distribution'], ansible_facts['distribution_major_version'], and related keys instead of ansible_distribution* variables.
  • Adjust templated messages and helper variables (e.g. __network_is_rh_distro, network_provider_os_default, gobject package selection, initscripts package selection) in defaults/main.yml to read from ansible_facts.
  • Ensure version and distro comparisons still use the same operators and integer casting semantics after the refactor.
tasks/main.yml
defaults/main.yml
Update the entire test suite (playbooks, helper tasks, and vars) to use ansible_facts-based access for distribution, version, OS family, and Python facts so tests run cleanly with INJECT_FACTS_AS_VARS=false.
  • Systematically replace ansible_distribution*, ansible_os_family, and related variables with ansible_facts[...] in all test playbooks and wrapper test files.
  • Update helper vars files (e.g. rh_distros_vars.yml) to derive distro classification flags from ansible_facts['distribution'].
  • Keep existing feature gating and test enable/skip conditions identical by mirroring the pre-refactor comparison logic with ansible_facts lookups.
tests/ensure_provider_tests.py
tests/playbooks/tests_routing_rules.yml
tests/tests_provider_nm.yml
tests/tests_regression_nm.yml
tests/playbooks/tests_ethernet.yml
tests/tasks/create_test_interfaces_with_dhcp.yml
tests/tests_802_1x_nm.yml
tests/tests_802_1x_updated_nm.yml
tests/tests_integration_pytest.yml
tests/playbooks/tests_ipv6.yml
tests/playbooks/tests_ipv6_dns_search.yml
tests/tasks/setup_802_1x_server.yml
tests/tasks/setup_mock_wifi_wpa3_owe.yml
tests/tasks/setup_mock_wifi_wpa3_sae.yml
tests/tests_team_nm.yml
tests/tests_team_plugin_installation_nm.yml
tests/tests_wireless_wpa3_owe_nm.yml
tests/playbooks/tests_wireless_wpa3_sae.yml
tests/tasks/el_repo_setup.yml
tests/tests_auto_gateway_initscripts.yml
tests/tests_bond_cloned_mac_initscripts.yml
tests/tests_bond_deprecated_initscripts.yml
tests/tests_bond_initscripts.yml
tests/tests_bond_removal_initscripts.yml
tests/tests_bridge_cloned_mac_initscripts.yml
tests/tests_bridge_initscripts.yml
tests/tests_default_initscripts.yml
tests/tests_eth_pci_address_match_nm.yml
tests/tests_ethernet_initscripts.yml
tests/tests_ethtool_coalesce_initscripts.yml
tests/tests_ethtool_coalesce_nm.yml
tests/tests_ethtool_features_initscripts.yml
tests/tests_ethtool_features_nm.yml
tests/tests_ethtool_ring_initscripts.yml
tests/tests_ethtool_ring_nm.yml
tests/tests_ipv6_initscripts.yml
tests/tests_mac_address_match_nm.yml
tests/tests_network_state_nm.yml
tests/tests_route_device_initscripts.yml
tests/tests_route_type_nm.yml
tests/tests_states_initscripts.yml
tests/tests_switch_provider.yml
tests/tests_vlan_mtu_initscripts.yml
tests/tests_wireless_nm.yml
tests/tests_wireless_wpa3_sae_nm.yml
tests/vars/rh_distros_vars.yml
tests/tests_auto_gateway_nm.yml
tests/tests_bond_cloned_mac_nm.yml
tests/tests_bond_deprecated_nm.yml
tests/tests_bond_nm.yml
tests/tests_bond_options_nm.yml
tests/tests_bond_port_match_by_mac_nm.yml
tests/tests_bond_removal_nm.yml
tests/tests_bridge_cloned_mac_nm.yml
tests/tests_bridge_nm.yml
tests/tests_default_nm.yml
tests/tests_dummy_nm.yml
tests/tests_eth_dns_support_nm.yml
tests/tests_ethernet_nm.yml
tests/tests_helpers_and_asserts.yml
tests/tests_ignore_auto_dns_nm.yml
tests/tests_infiniband_nm.yml
tests/tests_ipv6_disabled_nm.yml
tests/tests_ipv6_dns_search_nm.yml
tests/tests_ipv6_nm.yml
tests/tests_reapply_nm.yml
tests/tests_route_device_nm.yml
tests/tests_route_table_nm.yml
tests/tests_routing_rules_nm.yml
tests/tests_states_nm.yml
tests/tests_unit.yml
tests/tests_vlan_mtu_nm.yml
tests/tests_wireless_and_network_restart_nm.yml
tests/tests_wireless_plugin_installation_nm.yml

Possibly linked issues

  • #INJECT_FACTS_AS_VARS default to True is deprecated warnings with Ansible 2.20: PR changes ansible_distribution* and related facts to ansible_facts usage in tasks/defaults, eliminating the reported deprecation warnings.

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.

@codecov
Copy link

codecov bot commented Jan 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 43.22%. Comparing base (1b57520) to head (04d69c5).
⚠️ Report is 60 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #832      +/-   ##
==========================================
+ Coverage   43.11%   43.22%   +0.10%     
==========================================
  Files          12       12              
  Lines        3124     3123       -1     
==========================================
+ Hits         1347     1350       +3     
+ Misses       1777     1773       -4     

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

richm commented Jan 7, 2026

[citest]

@richm
Copy link
Contributor Author

richm commented Jan 7, 2026

fixes #829

@richm
Copy link
Contributor Author

richm commented Jan 7, 2026

qemu tests failing because ipv6 is disabled

@richm richm merged commit 39ac91d into linux-system-roles:main Jan 7, 2026
36 of 42 checks passed
@richm richm deleted the inject-facts-as-vars branch January 7, 2026 23:43
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