Skip to content

Conversation

@richm
Copy link
Collaborator

@richm richm commented Jan 6, 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 tests to use ansible_facts lookups instead of deprecated fact variables, ensuring compatibility with INJECT_FACTS_AS_VARS=false and newer Ansible versions.

Enhancements:

  • Replace direct use of deprecated Ansible fact variables with ansible_facts mappings across role defaults, templates, and tasks.
  • Expand the set of required Ansible facts and fact subsets to include domain, hostname, fqdn, and package manager metadata.

Documentation:

  • Refresh README and ostree documentation examples to reference ansible_facts-based variables instead of deprecated fact names.

Tests:

  • Adjust test playbooks and vars files to use ansible_facts-based distribution and OS metadata in conditions and examples.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 6, 2026

Reviewer's Guide

Refactors the role and tests to stop using deprecated top-level Ansible fact variables and instead consistently reference facts via ansible_facts, updating required fact lists, conditionals, templates, task commands, and documentation accordingly.

File-Level Changes

Change Details Files
Replace deprecated top-level Ansible fact variables with ansible_facts lookups and align required fact metadata, conditionals, templates, and docs with the new pattern.
  • Update logging_domain default expression to use ansible_facts['domain'] and ansible_facts['hostname'] instead of ansible_domain and ansible_hostname.
  • Extend and reorder __logging_required_facts to explicitly include all fact keys now referenced via ansible_facts, including default_ipv4, domain, fqdn, hostname, and pkg_mgr.
  • Change distro-detection helper variables (__logging_is_rh_distro and __logging_is_rh_distro_fedora) to use ansible_facts['distribution'] both in the role defaults and in test vars.
  • Update test comments and examples to refer to ansible_facts['distribution'], ansible_facts['distribution_version'], ansible_facts['distribution_major_version'], and ansible_facts['os_family'] instead of the deprecated top-level variables.
  • Adjust the ostree README to describe DISTRO-VERSION in terms of ansible_facts['distribution'] and ansible_facts['distribution_version'].
  • Modify rsyslog input templates to use ansible_facts['fqdn'] and ansible_facts['default_ipv4']['address'] for hostname and IP address, and to gate RELP settings based on ansible_facts['distribution'] and ansible_facts['distribution_major_version'].
  • Update tests that branch on distribution and distribution_major_version (e.g., RELP and combination tests) to use ansible_facts-based conditionals.
  • Update README logging_domain documentation to match the new ansible_facts-based default expression.
  • Switch the package manager invocation in rsyslog core tasks to use ansible_facts['pkg_mgr'] instead of ansible_pkg_mgr.
defaults/main.yml
tests/tests_include_vars_from_parent.yml
README-ostree.md
roles/rsyslog/templates/input_ovirt.j2
roles/rsyslog/templates/input_relp.j2
tests/tests_combination.yml
tests/tests_relp.yml
tests/vars/rh_distros_vars.yml
README.md
roles/rsyslog/tasks/main_core.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
Collaborator Author

richm commented Jan 6, 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 2 issues, and left some high level feedback:

  • In the Jinja templates (e.g. input_ovirt.j2), the use of single quotes around ansible_facts keys inside single-quoted strings ('{{ ansible_facts['fqdn'] }}') will break parsing; switch either the outer quotes to double quotes or the inner ones to double quotes (e.g. "{{ ansible_facts['fqdn'] }}" or '{{ ansible_facts["fqdn"] }}').
  • Where you now access ansible_facts keys directly (e.g. ansible_facts['domain'], ansible_facts['hostname']), consider using ansible_facts.get('...') or providing a safe default in Jinja to avoid hard failures if a fact is missing or partially gathered.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the Jinja templates (e.g. input_ovirt.j2), the use of single quotes around ansible_facts keys inside single-quoted strings (`'{{ ansible_facts['fqdn'] }}'`) will break parsing; switch either the outer quotes to double quotes or the inner ones to double quotes (e.g. `"{{ ansible_facts['fqdn'] }}"` or `'{{ ansible_facts["fqdn"] }}'`).
- Where you now access ansible_facts keys directly (e.g. `ansible_facts['domain']`, `ansible_facts['hostname']`), consider using `ansible_facts.get('...')` or providing a safe default in Jinja to avoid hard failures if a fact is missing or partially gathered.

## Individual Comments

### Comment 1
<location> `roles/rsyslog/templates/input_ovirt.j2:57` </location>
<code_context>
   set $!message = $.ovirt!message;
   set $!level = $.ovirt!level;
-  set $!hostname = '{{ ansible_fqdn }}';
+  set $!hostname = '{{ ansible_facts['fqdn'] }}';
   set $!ovirt!cluster_name = '{{ __ovirt_vds_cluster_name }}';
-  set $!ipaddr4 = '{{ ansible_default_ipv4.address }}';
</code_context>

<issue_to_address>
**issue (bug_risk):** The quoting here is invalid Jinja and will likely break template rendering.

This line uses single quotes for both the Jinja expression and the dictionary key, which is invalid syntax. Use different quote types for the outer string and the key, e.g.

```j2
set $!hostname = '{{ ansible_facts["fqdn"] }}';
```

or:

```j2
set $!hostname = "{{ ansible_facts['fqdn'] }}";
```
</issue_to_address>

### Comment 2
<location> `roles/rsyslog/templates/input_ovirt.j2:59` </location>
<code_context>
+  set $!hostname = '{{ ansible_facts['fqdn'] }}';
   set $!ovirt!cluster_name = '{{ __ovirt_vds_cluster_name }}';
-  set $!ipaddr4 = '{{ ansible_default_ipv4.address }}';
+  set $!ipaddr4 = '{{ ansible_facts['default_ipv4']['address'] }}';
   set $!ovirt!engine_fqdn = '{{ __ovirt_engine_fqdn }}';
   set $.input_type = "ovirt";
</code_context>

<issue_to_address>
**issue (bug_risk):** Similar quoting issue here will cause a Jinja syntax error.

This uses single quotes for both the Jinja string and the dict keys, which is invalid. Use alternating quote styles, e.g.:

```j2
set $!ipaddr4 = '{{ ansible_facts["default_ipv4"]["address"] }}';
```

or:

```j2
set $!ipaddr4 = "{{ ansible_facts['default_ipv4']['address'] }}";
```
</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.

@richm richm force-pushed the inject-facts-as-vars branch from ac702e7 to 6c563c0 Compare January 6, 2026 23:35
@richm
Copy link
Collaborator Author

richm commented Jan 6, 2026

[citest]

…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 force-pushed the inject-facts-as-vars branch from 6c563c0 to 3f9681c Compare January 6, 2026 23:58
@richm
Copy link
Collaborator Author

richm commented Jan 7, 2026

[citest]

@richm richm merged commit 39ebc19 into linux-system-roles:main Jan 7, 2026
28 checks passed
@richm richm deleted the inject-facts-as-vars branch January 7, 2026 14:41
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