Skip to content

Conversation

@martinpitt
Copy link
Contributor

@martinpitt martinpitt commented Jun 14, 2025

Fixes for the f42/ansible 2.19 failures introduced in #128. This isn't complete yet, so starting with draft.

Summary by Sourcery

Fix failures under Ansible 2.19 by correcting variable references in header assertions and ensuring the systemd status check runs outside of check mode.

Bug Fixes:

  • Use __ansible_managed instead of ansible_managed in header content assertions.
  • Add check_mode: false to the systemctl is-system-running command to prevent it from being skipped in check mode.

Cause: The test used a temporary variable `ansible_managed`, but that is
a "magic" string constant. Ansible 2.19 does not permit assigning to it
any more.

Consequence: Tests failed with Ansible 2.19.

Fix: Rename the variable.
Cause: `systemctl is-system-running` was not called in `--check` mode.

Consequence: The "Determine if system is booted with systemd" step
failed in check mode as the `__is_system_running` variable was not
populated.

Fix: Force calling `systemctl is-system-running` in check mode. It does
not modify the system and the outcome is very influential for what the
role does.
@sourcery-ai
Copy link

sourcery-ai bot commented Jun 14, 2025

Reviewer's Guide

Ensures Ansible 2.19 compatibility by updating the managed header variable reference and disabling check_mode on the systemctl health check task.

Sequence Diagram: Impact of 'check_mode: false' on 'systemctl is-system-running' Task

sequenceDiagram
    participant Ansible
    participant SystemctlTask as "'systemctl is-system-running' Task\n(with check_mode: false)"
    participant Systemd

    Ansible->>SystemctlTask: Execute Task (even if Ansible is in global check_mode)
    SystemctlTask->>Systemd: systemctl is-system-running (actual execution)
    Systemd-->>SystemctlTask: Actual status
    SystemctlTask->>Ansible: Register __is_system_running
Loading

File-Level Changes

Change Details Files
Use __ansible_managed variable instead of ansible_managed in header tests
  • Assert presence of __ansible_managed in content instead of ansible_managed
  • Rename lookup variable to __ansible_managed for header template
tests/tasks/check_header.yml
Disable check_mode for systemctl is-system-running task
  • Add check_mode: false to the systemctl command
  • Ensure command doesn’t run in check mode to avoid failures
tasks/set_vars.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

@martinpitt
Copy link
Contributor Author

OK, necessary but not sufficient, but we can land the fixes in steps.

@martinpitt martinpitt marked this pull request as ready for review June 15, 2025 12:00
@martinpitt martinpitt requested a review from spetrosi as a code owner June 15, 2025 12:00
@martinpitt martinpitt merged commit cda5783 into linux-system-roles:main Jun 15, 2025
18 of 19 checks passed
@martinpitt martinpitt deleted the a219 branch June 15, 2025 12:00
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 @martinpitt - I've reviewed your changes - here's some feedback:

  • Consider supporting both ansible_managed and __ansible_managed in the header test so it still passes on older Ansible versions.
  • Instead of unconditionally disabling check_mode, consider wrapping that option in a version check (e.g. when: ansible_version.full is version('2.19', '>=')) or adding a comment explaining why it’s needed.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider supporting both `ansible_managed` and `__ansible_managed` in the header test so it still passes on older Ansible versions.
- Instead of unconditionally disabling `check_mode`, consider wrapping that option in a version check (e.g. `when: ansible_version.full is version('2.19', '>=')`) or adding a comment explaining why it’s needed.

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.

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