feat: add role fingerprints to syslog [citest_skip]#206
Merged
Conversation
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>
Reviewer's GuideImplements a new sr_fingerprint Ansible module that logs timestamped role begin/success markers to syslog, wires it into the template role at start and completion, and adds a journalctl-based test plus sanity ignore files for the local module library. Sequence diagram for role fingerprint logging begin/success flowsequenceDiagram
actor User
participant AnsibleController
participant TemplateRole
participant SrFingerprintModule
participant Syslog
User->>AnsibleController: Invoke template role
AnsibleController->>TemplateRole: Execute tasks/set_vars.yml
TemplateRole->>SrFingerprintModule: sr_fingerprint sr_message="begin system_role:template ..."
SrFingerprintModule->>SrFingerprintModule: _local_iso8601_no_microseconds()
SrFingerprintModule->>Syslog: module.log("begin system_role:template ... <timestamp>")
Syslog-->>SrFingerprintModule: Accept log entry
SrFingerprintModule-->>TemplateRole: exit_json(changed=False)
AnsibleController->>TemplateRole: Execute remaining role tasks
TemplateRole->>AnsibleController: Main tasks complete successfully
AnsibleController->>TemplateRole: Execute tasks/main.yml final task
TemplateRole->>SrFingerprintModule: sr_fingerprint sr_message="success system_role:template ..."
SrFingerprintModule->>SrFingerprintModule: _local_iso8601_no_microseconds()
SrFingerprintModule->>Syslog: module.log("success system_role:template ... <timestamp>")
Syslog-->>SrFingerprintModule: Accept log entry
SrFingerprintModule-->>TemplateRole: exit_json(changed=False)
TemplateRole-->>AnsibleController: Role completed with fingerprints logged
AnsibleController-->>User: Report role success
Sequence diagram for sr_fingerprint module behavior including check modesequenceDiagram
participant AnsibleController
participant SrFingerprintModule
participant AnsibleModule
participant Syslog
AnsibleController->>SrFingerprintModule: Call run_module(sr_message)
SrFingerprintModule->>AnsibleModule: Create AnsibleModule(argument_spec={sr_message}, supports_check_mode=True)
SrFingerprintModule->>SrFingerprintModule: _local_iso8601_no_microseconds()
SrFingerprintModule->>SrFingerprintModule: Build log_message = sr_message + timestamp
alt check_mode is True
AnsibleModule-->>AnsibleController: exit_json(changed=False, message="Check mode: message not logged - [log_message]")
else normal mode
SrFingerprintModule->>Syslog: AnsibleModule.log(log_message)
Syslog-->>SrFingerprintModule: Log entry stored
AnsibleModule-->>AnsibleController: exit_json(changed=False)
end
Class diagram for the new sr_fingerprint Ansible moduleclassDiagram
class SrFingerprintModule {
+run_module()
+main()
+_local_iso8601_no_microseconds() str
-log_message str
}
class AnsibleModule {
+params dict
+check_mode bool
+log(message str) void
+exit_json(**kwargs) void
}
SrFingerprintModule ..> AnsibleModule : uses
class SrMessageParameter {
+sr_message str
}
SrFingerprintModule ..> SrMessageParameter : reads
class TemplateRoleTasks {
+set_vars_yml
+main_yml
+sr_message_begin str
+sr_message_success str
}
TemplateRoleTasks ..> SrFingerprintModule : invokes
class SetVarsTask_RecordBeginFingerprint {
+name Record_role_begin_fingerprint
+module sr_fingerprint
+sr_message str
}
class MainTask_RecordSuccessFingerprint {
+name Record_role_success_fingerprint
+module sr_fingerprint
+sr_message str
}
TemplateRoleTasks *-- SetVarsTask_RecordBeginFingerprint
TemplateRoleTasks *-- MainTask_RecordSuccessFingerprint
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The fingerprint message format is duplicated in both the "begin" and "success" tasks; consider constructing the common prefix (role name, ansible_version, platform) once via a variable or template to keep the format consistent and easier to change later.
- The journalctl test greps for "sr_fingerprint.*begin system_role:template", but the module only logs the sr_message plus a timestamp; aligning the grep pattern with the actual log format (and avoiding unnecessary hard-coding of the module name/role name where possible) will make the test more robust and less brittle to internal logging prefix changes.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The fingerprint message format is duplicated in both the "begin" and "success" tasks; consider constructing the common prefix (role name, ansible_version, platform) once via a variable or template to keep the format consistent and easier to change later.
- The journalctl test greps for "sr_fingerprint.*begin system_role:template", but the module only logs the sr_message plus a timestamp; aligning the grep pattern with the actual log format (and avoiding unnecessary hard-coding of the module name/role name where possible) will make the test more robust and less brittle to internal logging prefix changes.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 role-specific syslog fingerprinting for template role runs and verify it via journal-based testing.
New Features:
Tests:
Chores: