feat: add role fingerprints to syslog#141
Merged
Merged
Conversation
Reviewer's GuideAdds a new sr_fingerprint Ansible module that logs role start/success fingerprints to syslog and wires it into the systemd role along with a journalctl-based test, plus sanity-ignore entries for the new module across multiple Ansible versions. Sequence diagram for role fingerprints being logged to syslogsequenceDiagram
actor User
participant AnsibleController
participant SystemdRole
participant Sr_fingerprint_module
participant Syslog
User->>AnsibleController: Run playbook including systemd_role
AnsibleController->>SystemdRole: Execute tasks/main.yml
Note over SystemdRole: Begin fingerprint task
SystemdRole->>Sr_fingerprint_module: Call sr_fingerprint sr_message="begin system_role:systemd ..."
Sr_fingerprint_module->>Sr_fingerprint_module: _local_iso8601_no_microseconds()
alt check_mode true
Sr_fingerprint_module-->>AnsibleController: exit_json(changed=false, message="Check mode: message not logged ...")
else check_mode false
Sr_fingerprint_module->>Syslog: module.log("begin ... <timestamp>")
Syslog-->>Sr_fingerprint_module: Log recorded
Sr_fingerprint_module-->>AnsibleController: exit_json(changed=false)
end
AnsibleController->>SystemdRole: Continue remaining role tasks
Note over SystemdRole: Success fingerprint task (on successful completion)
SystemdRole->>Sr_fingerprint_module: Call sr_fingerprint sr_message="success system_role:systemd ..."
Sr_fingerprint_module->>Sr_fingerprint_module: _local_iso8601_no_microseconds()
alt check_mode true
Sr_fingerprint_module-->>AnsibleController: exit_json(changed=false, message="Check mode: message not logged ...")
else check_mode false
Sr_fingerprint_module->>Syslog: module.log("success ... <timestamp>")
Syslog-->>Sr_fingerprint_module: Log recorded
Sr_fingerprint_module-->>AnsibleController: exit_json(changed=false)
end
AnsibleController-->>User: Playbook run complete
Class diagram for the new sr_fingerprint Ansible moduleclassDiagram
class Sr_fingerprint_module {
+run_module()
+main()
+_local_iso8601_no_microseconds()
}
class AnsibleModule {
+params
+check_mode
+log(message)
+exit_json(changed, message)
}
Sr_fingerprint_module ..> AnsibleModule : uses
class Sr_message_param {
+sr_message : str
}
Sr_fingerprint_module ..> Sr_message_param : reads
class Datetime_helpers {
+datetime_now()
+time_localtime()
+strftime()
+astimezone()
}
Sr_fingerprint_module ..> Datetime_helpers : constructs_timestamp
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
Author
|
[citest] |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The fingerprint message format is duplicated in the begin/success tasks in
tasks/main.yml; consider extracting the common prefix/suffix (role name, ansible_version, distro info) into a variable to avoid drift if the format ever changes. - The journalctl-based test hardcodes the grep patterns for
sr_fingerprint.*begin system_role:systemdandsuccess system_role:systemd; if the role name or format changes, this will silently become stale, so you might want to build these patterns from a shared variable to keep them aligned with thesr_fingerprintcalls.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The fingerprint message format is duplicated in the begin/success tasks in `tasks/main.yml`; consider extracting the common prefix/suffix (role name, ansible_version, distro info) into a variable to avoid drift if the format ever changes.
- The journalctl-based test hardcodes the grep patterns for `sr_fingerprint.*begin system_role:systemd` and `success system_role:systemd`; if the role name or format changes, this will silently become stale, so you might want to build these patterns from a shared variable to keep them aligned with the `sr_fingerprint` calls.
## Individual Comments
### Comment 1
<location path="tasks/main.yml" line_range="10-12" />
<code_context>
length > 0
vars:
__required_facts:
- - distribution
- - distribution_major_version
- - os_family
+ - distribution
+ - distribution_major_version
</code_context>
<issue_to_address>
**issue (bug_risk):** List indentation under `__required_facts` likely breaks YAML structure.
The `- distribution` items are now siblings of `__required_facts` instead of values under it, which alters the resulting data (and may even invalidate the YAML). Please re-indent the list so it remains nested under `__required_facts`.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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>
Contributor
Author
|
[citest] |
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 a role-internal fingerprinting mechanism that logs begin/success markers to syslog when the systemd role runs and verify them via tests.
New Features:
Tests:
Chores: