Skip to content

fix: use ansible_facts timesync_ntp_provider_current#331

Merged
richm merged 1 commit intolinux-system-roles:mainfrom
richm:fix-use-ansible_facts-timesync_ntp_provider_current
Feb 12, 2026
Merged

fix: use ansible_facts timesync_ntp_provider_current#331
richm merged 1 commit intolinux-system-roles:mainfrom
richm:fix-use-ansible_facts-timesync_ntp_provider_current

Conversation

@richm
Copy link
Collaborator

@richm richm commented Feb 12, 2026

Cause: When using ANSIBLE_INJECT_FACT_VARS=false, the fact timesync_ntp_provider_current
is not made into a top level variable.

Consequence: The current timesync provider cannot be determined.

Fix: Use the value from ansible_facts.

Result: The timesync provider is correctly determined.

Signed-off-by: Rich Megginson rmeggins@redhat.com

Summary by Sourcery

Bug Fixes:

  • Fix NTP provider selection to read timesync_ntp_provider_current from ansible_facts so it works with ANSIBLE_INJECT_FACT_VARS disabled.

Cause: When using ANSIBLE_INJECT_FACT_VARS=false, the fact timesync_ntp_provider_current
is not made into a top level variable.

Consequence: The current timesync provider cannot be determined.

Fix: Use the value from ansible_facts.

Result: The timesync provider is correctly determined.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
@sourcery-ai
Copy link

sourcery-ai bot commented Feb 12, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the timesync role to read the current NTP provider from ansible_facts instead of a top-level variable, ensuring correct behavior when ANSIBLE_INJECT_FACT_VARS is disabled, and registers the provider discovery task result for later use if needed.

Sequence diagram for NTP provider selection in timesync role

sequenceDiagram
    actor AnsibleUser
    participant AnsibleController
    participant ManagedHost
    participant AnsibleFacts

    AnsibleUser->>AnsibleController: Run timesync role
    AnsibleController->>ManagedHost: Gather facts
    ManagedHost-->>AnsibleController: ansible_facts including timesync_ntp_provider_current

    AnsibleController->>ManagedHost: Task ensure timesync_ntp_provider is empty
    ManagedHost-->>AnsibleController: timesync_provider_result

    AnsibleController->>ManagedHost: Task Select NTP provider
    Note over AnsibleController,ManagedHost: When timesync_mode != 2 and timesync_ntp_provider is empty
    AnsibleController->>AnsibleFacts: Read ansible_facts timesync_ntp_provider_current
    AnsibleFacts-->>AnsibleController: timesync_ntp_provider_current
    AnsibleController->>ManagedHost: set_fact timesync_ntp_provider from ansible_facts or default

    AnsibleController-->>AnsibleUser: timesync_ntp_provider correctly determined
Loading

Flow diagram for timesync_ntp_provider determination logic

flowchart TD
    A[timesync_mode != 2?] -->|no| B[Skip provider detection]
    A -->|yes| C[timesync_ntp_provider length == 0?]
    C -->|no| B
    C -->|yes| D[Run provider discovery task<br/>register timesync_provider_result]
    D --> E[Select NTP provider<br/>set_fact timesync_ntp_provider = ansible_facts&#91;timesync_ntp_provider_current&#93; or timesync_ntp_provider_os_default]
    E --> F[Use timesync_ntp_provider for further tasks]
Loading

File-Level Changes

Change Details Files
Use ansible_facts to resolve the current timesync NTP provider instead of relying on an injected top-level fact variable.
  • Register the result of the current NTP provider discovery task into a variable for potential downstream use.
  • Change the NTP provider selection logic to read timesync_ntp_provider_current from ansible_facts rather than assuming it is a top-level variable.
  • Retain the existing fallback to the OS default NTP provider when the current provider fact is absent.
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

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:

  • Accessing ansible_facts['timesync_ntp_provider_current'] directly will fail if the key is absent; consider using ansible_facts.timesync_ntp_provider_current | default(...) or ansible_facts.get('timesync_ntp_provider_current') | default(...) so the default filter can actually guard against missing data.
  • The newly added register: timesync_provider_result is not used anywhere in this diff; if it’s not needed, remove it to avoid confusion about its purpose.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Accessing `ansible_facts['timesync_ntp_provider_current']` directly will fail if the key is absent; consider using `ansible_facts.timesync_ntp_provider_current | default(...)` or `ansible_facts.get('timesync_ntp_provider_current') | default(...)` so the `default` filter can actually guard against missing data.
- The newly added `register: timesync_provider_result` is not used anywhere in this diff; if it’s not needed, remove it to avoid confusion about its purpose.

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
Copy link
Collaborator Author

richm commented Feb 12, 2026

[citest]

@richm richm merged commit 15df717 into linux-system-roles:main Feb 12, 2026
29 of 30 checks passed
@richm richm deleted the fix-use-ansible_facts-timesync_ntp_provider_current branch February 12, 2026 19: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.

1 participant