Skip to content

Conversation

@richm
Copy link
Collaborator

@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 Ansible role and tests to use ansible_facts-based lookups instead of legacy fact variables to comply with INJECT_FACTS_AS_VARS=false and upcoming Ansible deprecations.

Enhancements:

  • Replace direct use of injected Ansible fact variables (e.g. ansible_distribution, ansible_default_ipv4) with ansible_facts lookups across role vars, templates, and test playbooks.
  • Quote network interface values in shell/command invocations to ensure safe handling of fact-derived interface names.

…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]>
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 8, 2026

Reviewer's Guide

Refactors Ansible role and test playbooks to stop using deprecated fact-as-variable shortcuts and instead consistently reference data via ansible_facts, with a few related quoting hardenings in shell/command invocations.

File-Level Changes

Change Details Files
Replace deprecated fact variables (e.g., ansible_distribution, ansible_default_ipv4) with ansible_facts lookups throughout tests and role vars.
  • Update interface references from ansible_default_ipv4['interface'] to ansible_facts['default_ipv4']['interface'] in timesync PTP-related test playbooks.
  • Change distribution checks from ansible_distribution/ansible_distribution_version to ansible_facts['distribution']/ansible_facts['distribution_version'] in test conditionals.
  • Switch helper vars that classify Red Hat distributions to compute against ansible_facts['distribution'] instead of ansible_distribution.
  • Update ntpd sysconfig template OPTIONS expression to use ansible_facts['distribution'] and ansible_facts['distribution_major_version'] for distro-specific logic.
tests/tests_ptp_multi.yml
tests/tests_ptp_single.yml
tests/tests_ntp_ptp.yml
tests/tests_ntp_provider6.yml
tests/vars/rh_distros_vars.yml
vars/main.yml
templates/ntpd.sysconfig.j2
Tighten command invocations by quoting interface arguments to improve safety and consistency.
  • Quote the interface parameter in ethtool -T command invocations using ansible_facts['default_ipv4']['interface']
quote.
  • Quote the interface value passed to phc_ctl in the main tasks file using Jinja2's quote filter.

  • 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 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 found 1 issue, and left some high level feedback:

    • Now that everything is using ansible_facts[...], consider switching to dot-notation (e.g. ansible_facts.default_ipv4.interface) for readability and to match common Ansible style, as it’s equivalent here.
    • You have several repeated inline distro checks using ansible_facts['distribution'] / distribution_version; where possible, consider reusing the existing helper vars like __timesync_is_rh_distro(_fedora) to keep the logic centralized and easier to maintain.
    Prompt for AI Agents
    Please address the comments from this code review:
    
    ## Overall Comments
    - Now that everything is using `ansible_facts[...]`, consider switching to dot-notation (e.g. `ansible_facts.default_ipv4.interface`) for readability and to match common Ansible style, as it’s equivalent here.
    - You have several repeated inline distro checks using `ansible_facts['distribution']` / `distribution_version`; where possible, consider reusing the existing helper vars like `__timesync_is_rh_distro(_fedora)` to keep the logic centralized and easier to maintain.
    
    ## Individual Comments
    
    ### Comment 1
    <location> `tasks/main.yml:141` </location>
    <code_context>
    
     - name: Run phc_ctl on PTP interface
    -  command: phc_ctl -q {{ timesync_ptp_domains[0].interfaces[0] }}
    +  command: phc_ctl -q {{ timesync_ptp_domains[0].interfaces[0] | quote }}
       register: timesync_phc_ctl_output
       changed_when: false
    </code_context>
    
    <issue_to_address>
    **issue (bug_risk):** Using `quote` with the `command` module will pass literal quotes to `phc_ctl`, likely breaking the argument.
    
    Because `command` does not use a shell, it passes arguments as-is after splitting on whitespace. Using `| quote` turns `eth0` into `'eth0'`, including the single quotes, which `phc_ctl` is unlikely to accept and may cause failures.
    
    If you just want to safely pass the interface, keep `command` and remove `| quote`, e.g.:
    
    ```yaml
    action: phc_ctl -q "{{ timesync_ptp_domains[0].interfaces[0] }}"
    ```
    
    Only use `| quote` if you switch to the `shell` module and actually need shell-escaping semantics.
    </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.


    - name: Run phc_ctl on PTP interface
    command: phc_ctl -q {{ timesync_ptp_domains[0].interfaces[0] }}
    command: phc_ctl -q {{ timesync_ptp_domains[0].interfaces[0] | quote }}
    Copy link

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    issue (bug_risk): Using quote with the command module will pass literal quotes to phc_ctl, likely breaking the argument.

    Because command does not use a shell, it passes arguments as-is after splitting on whitespace. Using | quote turns eth0 into 'eth0', including the single quotes, which phc_ctl is unlikely to accept and may cause failures.

    If you just want to safely pass the interface, keep command and remove | quote, e.g.:

    action: phc_ctl -q "{{ timesync_ptp_domains[0].interfaces[0] }}"

    Only use | quote if you switch to the shell module and actually need shell-escaping semantics.

    @richm richm merged commit ebd4a7a into linux-system-roles:main Jan 8, 2026
    41 of 42 checks passed
    @richm richm deleted the inject-facts-as-vars branch January 8, 2026 19:20
    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