Skip to content

Conversation

@richm
Copy link
Collaborator

@richm richm commented Sep 9, 2025

Feature: Support running the timesync role during container builds.

Reason: This is particularly useful for building bootc derivative OSes.

Result: These flags enable running the bootc container scenarios in CI,
which ensures that the role works in buildah build environment. This
allows us to officially support this role for image mode builds.

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

Summary by Sourcery

Enable the timesync Ansible role to operate correctly in container build environments by detecting whether the system is booted and adjusting service discovery, start/stop operations, and CI tests accordingly.

New Features:

  • Detect runtime availability of systemd via a new __timesync_is_booted fact
  • Provide alternative tasks to list and set timesync services when systemd is not available in container builds
  • Guard all service start/stop/restart operations behind the __timesync_is_booted check to skip state changes during container builds

Enhancements:

  • Add a galaxy tag for containerbuild support

Tests:

  • Update CI tests to run buildah container scenarios via QEMU and conditionally execute only variable setup in bootc validation mode

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 9, 2025

Reviewer's Guide

This PR introduces a __timesync_is_booted flag to detect systemd runtime availability in container build environments and conditionally alters service discovery, state management, handler execution, and testing flow to support running the timesync role under buildah scenarios, alongside adding a metadata tag for container builds.

Sequence diagram for conditional service management based on booted state

sequenceDiagram
    participant Ansible
    participant System
    participant Service
    Ansible->>System: Run "systemctl is-system-running"
    System-->>Ansible: Return status (e.g., 'offline', 'running')
    Ansible->>Ansible: Set __timesync_is_booted flag
    alt __timesync_is_booted is true
        Ansible->>Service: Manage service state (start/stop/enable/disable)
    else __timesync_is_booted is false
        Ansible->>System: List unit files via "systemctl list-unit-files"
        System-->>Ansible: Return service list
        Ansible->>Ansible: Set timesync_services fact
        Ansible->>Service: Only enable/disable, omit state changes
    end
Loading

Class diagram for timesync role variables and service management

classDiagram
    class TimesyncRole {
        +__timesync_is_booted: bool
        +timesync_services: list
        +Service Management (conditional on __timesync_is_booted)
    }
    class Service {
        +name: string
        +state: string ("started", "stopped", or omitted)
        +enabled: bool
    }
    TimesyncRole "1" -- "*" Service : manages
    TimesyncRole : determines __timesync_is_booted
    TimesyncRole : sets timesync_services
    Service : state set only if __timesync_is_booted
    Service : enabled always set
Loading

File-Level Changes

Change Details Files
Detect systemd runtime availability in set_vars
  • Run systemctl is-system-running to check for systemd boot state
  • Fail early if systemd is not installed
  • Set __timesync_is_booted fact based on systemctl output
tasks/set_vars.yml
Conditional service enumeration and state management based on build context
  • Add alternative list-unit-files command path when __timesync_is_booted is false
  • Guard existing service_facts and set_fact tasks with __timesync_is_booted condition
  • Replace static service state entries with conditional templates using omit
tasks/main.yml
Guard handler executions with build context flag
  • Add when: __timesync_is_booted checks to all service restart handlers
handlers/main.yml
Extend tests to support container build validation
  • Split role invocation into full and set_vars-only phases based on __bootc_validation
  • Add QEMU deployment step for buildah end-to-end scenario
tests/tests_chrony.yml
Add containerbuild tag in metadata
  • Include 'containerbuild' in galaxy_tags
meta/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 there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `handlers/main.yml:6` </location>
<code_context>
   service:
     name: chronyd
     state: restarted
+  when: __timesync_is_booted | d(false)

 - name: Restart ntpd
</code_context>

<issue_to_address>
Handler will be skipped if __timesync_is_booted is not set.

Confirm that skipping the handler when __timesync_is_booted is undefined is intentional, as this may affect environments where the variable is missing.
</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.

service:
name: chronyd
state: restarted
when: __timesync_is_booted | d(false)
Copy link

Choose a reason for hiding this comment

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

question: Handler will be skipped if __timesync_is_booted is not set.

Confirm that skipping the handler when __timesync_is_booted is undefined is intentional, as this may affect environments where the variable is missing.

@richm
Copy link
Collaborator Author

richm commented Sep 10, 2025

[citest]

@richm
Copy link
Collaborator Author

richm commented Sep 10, 2025

[citest]

Feature: Support running the timesync role during container builds.

Reason: This is particularly useful for building bootc derivative OSes.

Result: These flags enable running the bootc container scenarios in CI,
which ensures that the role works in buildah build environment. This
allows us to officially support this role for image mode builds.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
@richm richm merged commit ad162d5 into linux-system-roles:main Sep 12, 2025
20 checks passed
@richm richm deleted the bootc branch September 12, 2025 20:36
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.

2 participants