Skip to content

Conversation

@richm
Copy link
Contributor

@richm richm commented Jan 8, 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 [email protected]

Summary by Sourcery

Update role and documentation to use ansible_facts instead of deprecated fact variables.

Enhancements:

  • Replace direct fact variables (e.g. ansible_distribution, ansible_default_ipv4) with ansible_facts lookups for distribution and default IP detection logic.
  • Clarify controller OpenSSL installation behavior when using become in the main task file.

Documentation:

  • Adjust README-ostree documentation to reference ansible_facts-based distro and version variables instead of deprecated Ansible fact variables.

Tests:

  • Update test playbooks and test vars to use ansible_facts-based distribution checks and comments, aligning tests with the new fact access pattern.

…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 <[email protected]>
@richm richm requested a review from ueno as a code owner January 8, 2026 18:45
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 8, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors the role and its tests/docs to stop using deprecated top-level Ansible fact variables (e.g. ansible_distribution, ansible_default_ipv4) and instead access them via the ansible_facts dict, ensuring compatibility with INJECT_FACTS_AS_VARS=false on newer Ansible versions.

Sequence diagram for accessing Ansible facts via ansible_facts with INJECT_FACTS_AS_VARS=false

sequenceDiagram
    actor User
    participant AnsibleController
    participant AnsibleFactsSystem
    participant VpnRole

    User->>AnsibleController: run ansible_playbook
    AnsibleController->>AnsibleFactsSystem: gather_facts
    AnsibleFactsSystem-->>AnsibleController: ansible_facts dict

    AnsibleController->>VpnRole: execute role tasks with ansible_facts

    VpnRole->>VpnRole: compute __vpn_is_rh_distro
    Note over VpnRole: __vpn_is_rh_distro = ansible_facts['distribution'] in __vpn_rh_distros

    VpnRole->>VpnRole: compute __vpn_is_rh_distro_fedora
    Note over VpnRole: __vpn_is_rh_distro_fedora = ansible_facts['distribution'] in __vpn_rh_distros_fedora

    VpnRole->>VpnRole: compute __vpn_current_ip
    Note over VpnRole: __vpn_current_ip = ansible_facts['default_ipv4'].address | d(ansible_facts['default_ipv6'].address)

    VpnRole-->>AnsibleController: tasks complete without using top_level facts
    AnsibleController-->>User: playbook run completes without deprecation warnings
Loading

File-Level Changes

Change Details Files
Update fact usage in tests to reference ansible_facts instead of deprecated top-level fact variables.
  • Adjust commented example templates in the include-vars test playbook from ansible_distribution*/ansible_os_family to ansible_facts["distribution"*]/ansible_facts["os_family"] so tests and documentation reflect the new facts style.
tests/tests_include_vars_from_parent.yml
Align README documentation with new Ansible facts access pattern.
  • Change README description of DISTRO-VERSION to refer to ansible_facts["distribution"] and ansible_facts["distribution_version"] instead of deprecated ansible_distribution and ansible_distribution_version.
README-ostree.md
Refactor distro-detection variables to use ansible_facts["distribution"] in conditionals.
  • Update __vpn_is_rh_distro and __vpn_is_rh_distro_fedora expressions in test vars to check ansible_facts['distribution'] membership in distro lists.
  • Make the same change in the main role vars so runtime behavior no longer relies on injected fact variables.
tests/vars/rh_distros_vars.yml
vars/main.yml
Use ansible_facts for IP detection instead of top-level default IPv4/IPv6 facts and clarify controller sudo behavior.
  • Change __vpn_current_ip computation to read ansible_facts['default_ipv4'].address and ansible_facts['default_ipv6'].address instead of ansible_default_ipv4/ansible_default_ipv6.
  • Add a comment explaining that installing OpenSSL on the controller requires running Ansible with become=true (e.g. ansible-playbook --become ...).
tasks/mesh_conf.yml
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

@richm
Copy link
Contributor Author

richm commented Jan 8, 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 left some high level feedback:

  • In tasks/mesh_conf.yml, ansible_facts['default_ipv4'].address and the IPv6 equivalent should use dictionary-style access (ansible_facts['default_ipv4']['address']) rather than attribute access to avoid runtime errors, since ansible_facts['default_ipv4'] is a dict, not an object.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `tasks/mesh_conf.yml`, `ansible_facts['default_ipv4'].address` and the IPv6 equivalent should use dictionary-style access (`ansible_facts['default_ipv4']['address']`) rather than attribute access to avoid runtime errors, since `ansible_facts['default_ipv4']` is a dict, not an object.

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 a8764a3 into linux-system-roles:main Jan 8, 2026
38 checks passed
@richm richm deleted the inject-facts-as-vars branch January 8, 2026 19:00
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