Skip to content

feat: add role fingerprints to syslog - #250

Merged
richm merged 1 commit into
linux-system-roles:mainfrom
richm:fingerprint
Apr 27, 2026
Merged

feat: add role fingerprints to syslog#250
richm merged 1 commit into
linux-system-roles:mainfrom
richm:fingerprint

Conversation

@richm

@richm richm commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Feature: Add a fingerprint string to the system log to indicate when the role began
successfully, and when the role finished successfully. The fingerprint string indicates
the role name, a timestamp, and the platform.

Reason: Users can see when the role was used and if it was used successfully. This
information from the system log can be collected by log scanners and aggregators
for further analysis.

Result: The role logs fingerprints to the system log.

This also adds a test to check if the fingerprints were written upon a successful
role invocation.

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

Summary by Sourcery

Add syslog fingerprinting for the VPN system role and verify its presence in the system journal during tests.

New Features:

  • Introduce an sr_fingerprint Ansible module to write timestamped fingerprint messages to syslog.
  • Emit begin and success fingerprint messages from the VPN role including role name, Ansible version, and platform details.

Tests:

  • Extend the default role test to verify that the expected begin and success fingerprint messages appear in the system journal when /dev/log is available.

Chores:

  • Add Ansible sanity ignore configuration files for additional Ansible core versions.

@richm
richm requested a review from ueno as a code owner April 27, 2026 19:24
@sourcery-ai

sourcery-ai Bot commented Apr 27, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a custom sr_fingerprint Ansible module to write role fingerprint messages to syslog, wires it into the VPN role at begin/success entry points, and extends the default test to validate that the fingerprints are emitted via journalctl when syslog is available, along with the necessary sanity ignore and library wiring for the role tests.

Sequence diagram for VPN role fingerprints written to syslog

sequenceDiagram
  actor User
  participant AnsibleController
  participant VPNRole
  participant sr_fingerprint
  participant Syslog

  User->>AnsibleController: Run_playbook_with_vpn_role
  AnsibleController->>VPNRole: Execute_tasks

  rect rgb(230,230,255)
    VPNRole->>sr_fingerprint: Record_role_begin_fingerprint(sr_message)
    activate sr_fingerprint
    sr_fingerprint->>sr_fingerprint: _local_iso8601_no_microseconds()
    sr_fingerprint->>Syslog: module.log("begin system_role:vpn ... <timestamp>")
    sr_fingerprint-->>VPNRole: exit_json(changed=False)
    deactivate sr_fingerprint
  end

  VPNRole->>VPNRole: Configure_VPN_resources

  rect rgb(230,255,230)
    VPNRole->>sr_fingerprint: Record_role_success_fingerprint(sr_message)
    activate sr_fingerprint
    sr_fingerprint->>sr_fingerprint: _local_iso8601_no_microseconds()
    sr_fingerprint->>Syslog: module.log("success system_role:vpn ... <timestamp>")
    sr_fingerprint-->>VPNRole: exit_json(changed=False)
    deactivate sr_fingerprint
  end

  VPNRole-->>AnsibleController: Role_completed
  AnsibleController-->>User: Report_success
Loading

Class diagram for the new sr_fingerprint Ansible module

classDiagram
  class sr_fingerprint_module {
    +run_module()
    +main()
    -_local_iso8601_no_microseconds()
  }

  class AnsibleModule {
    +params
    +check_mode
    +log(msg)
    +exit_json(changed, message)
  }

  sr_fingerprint_module ..> AnsibleModule : uses

  class FingerprintLoggingFlow {
    +sr_message : str
    +log_message : str
    +compose_log_message(sr_message)
    +log_with_timestamp()
  }

  sr_fingerprint_module ..> FingerprintLoggingFlow : internal_logic

  class VPNRoleTasks {
    +Record_role_begin_fingerprint
    +Record_role_success_fingerprint
  }

  VPNRoleTasks ..> sr_fingerprint_module : invokes

  class TimestampSource {
    +_local_iso8601_no_microseconds()
  }

  sr_fingerprint_module ..> TimestampSource : obtains_timestamp
Loading

File-Level Changes

Change Details Files
Introduce sr_fingerprint Ansible module to log fingerprint messages to syslog with a standardized timestamped format and support check mode without reporting changes.
  • Create custom sr_fingerprint module that accepts a required sr_message string parameter.
  • Implement helper to generate local ISO-8601 timestamps without microseconds, compatible with older Python versions.
  • Compose log message from sr_message and timestamp, log via module.log, and always exit with changed set to false.
  • Support Ansible check mode by not logging but returning a descriptive message instead.
library/sr_fingerprint.py
Emit begin and success fingerprint log entries from the VPN role using the new module, including role name, Ansible version, and platform details.
  • Add a 'Record role begin fingerprint' task early in set_vars to log a begin system_role:vpn message that includes ansible_version and distribution/version facts.
  • Add a 'Record role success fingerprint' task at the end of the main role tasks to log a success system_role:vpn message with the same metadata.
  • Ensure the fingerprint messages have a consistent format suitable for log collection and analysis.
tasks/set_vars.yml
tasks/main.yml
Extend the default role test to verify that begin/success fingerprints are written to the system journal when syslog is available.
  • Before running the role, stat /dev/log and record a journal start timestamp from ansible_facts if syslog is present.
  • After role execution, run journalctl from the recorded time and grep for begin and success fingerprint messages for system_role:vpn, filtering out noisy 'Invoked with' lines.
  • Fail the test explicitly with clear error messages if either BEGIN or SUCCESS fingerprints are not found, and mark the shell task as not changing state.
  • Wire the test role library directory to make the custom module available during testing.
tests/tests_default.yml
tests/roles/linux-system-roles.vpn/library
Update Ansible sanity ignore files to account for the new custom module across supported Ansible versions.
  • Add or update .sanity-ansible-ignore files for multiple Ansible versions (2.9 through 2.22) so that the custom sr_fingerprint module and related layout do not trigger sanity failures.
.sanity-ansible-ignore-2.9.txt
.sanity-ansible-ignore-2.10.txt
.sanity-ansible-ignore-2.11.txt
.sanity-ansible-ignore-2.12.txt
.sanity-ansible-ignore-2.13.txt
.sanity-ansible-ignore-2.14.txt
.sanity-ansible-ignore-2.15.txt
.sanity-ansible-ignore-2.16.txt
.sanity-ansible-ignore-2.17.txt
.sanity-ansible-ignore-2.18.txt
.sanity-ansible-ignore-2.19.txt
.sanity-ansible-ignore-2.20.txt
.sanity-ansible-ignore-2.21.txt
.sanity-ansible-ignore-2.22.txt

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

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:

  • The sr_message format string for the begin/success fingerprints is duplicated in set_vars.yml and tasks/main.yml; consider centralizing the construction of this message (e.g. via a variable or included task) so changes to the format only need to be made in one place.
  • The test that checks for fingerprints invokes journalctl twice with the same --since filter; you could simplify and make this slightly less brittle by calling journalctl once and grepping for both begin and success fingerprints in that single output.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `sr_message` format string for the begin/success fingerprints is duplicated in `set_vars.yml` and `tasks/main.yml`; consider centralizing the construction of this message (e.g. via a variable or included task) so changes to the format only need to be made in one place.
- The test that checks for fingerprints invokes `journalctl` twice with the same `--since` filter; you could simplify and make this slightly less brittle by calling `journalctl` once and grepping for both begin and success fingerprints in that single output.

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.

@codecov

codecov Bot commented Apr 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 33 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@d445cb8). Learn more about missing BASE report.

Files with missing lines Patch % Lines
library/sr_fingerprint.py 0.00% 33 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##             main    #250   +/-   ##
======================================
  Coverage        ?   0.00%           
======================================
  Files           ?       1           
  Lines           ?      33           
  Branches        ?       0           
======================================
  Hits            ?       0           
  Misses          ?      33           
  Partials        ?       0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Feature: Add a fingerprint string to the system log to indicate when the role began
successfully, and when the role finished successfully.  The fingerprint string indicates
the role name, a timestamp, and the platform.

Reason: Users can see when the role was used and if it was used successfully.  This
information from the system log can be collected by log scanners and aggregators
for further analysis.

Result: The role logs fingerprints to the system log.

This also adds a test to check if the fingerprints were written upon a successful
role invocation.

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

richm commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

[citest]

@richm
richm merged commit 94d31fa into linux-system-roles:main Apr 27, 2026
46 checks passed
@richm
richm deleted the fingerprint branch April 27, 2026 20:48
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