feat: add role fingerprints to syslog#113
Conversation
Reviewer's GuideThis PR introduces a new sr_fingerprint Ansible module that writes structured role "begin" and "success" fingerprints to syslog, wires it into the sudo system role, and adds a journal-based test that verifies the fingerprints are emitted when the role runs successfully, while also adjusting Ansible sanity ignores and removing several markdown documentation files from the collection. Sequence diagram for sudo role fingerprints being written to syslogsequenceDiagram
actor Operator
participant AnsibleController
participant SudoRole
participant sr_fingerprint
participant Syslog
Operator->>AnsibleController: Run sudo_system_role
AnsibleController->>SudoRole: Execute tasks
%% Begin fingerprint
SudoRole->>sr_fingerprint: sr_message="begin system_role:sudo ..."
activate sr_fingerprint
sr_fingerprint->>sr_fingerprint: _local_iso8601_no_microseconds()
sr_fingerprint->>Syslog: module.log("begin system_role:sudo ... <timestamp>")
sr_fingerprint-->>SudoRole: exit_json(changed=False)
deactivate sr_fingerprint
SudoRole->>SudoRole: Configure sudo as usual
%% Success fingerprint
SudoRole->>sr_fingerprint: sr_message="success system_role:sudo ..."
activate sr_fingerprint
sr_fingerprint->>sr_fingerprint: _local_iso8601_no_microseconds()
sr_fingerprint->>Syslog: module.log("success system_role:sudo ... <timestamp>")
sr_fingerprint-->>SudoRole: exit_json(changed=False)
deactivate sr_fingerprint
SudoRole-->>AnsibleController: Role completed successfully
AnsibleController-->>Operator: Report success and fingerprints available in syslog
Class diagram for the new sr_fingerprint Ansible module and its use in the sudo roleclassDiagram
class sr_fingerprint_module {
+run_module()
+main()
+_local_iso8601_no_microseconds() str
}
class AnsibleModule {
+log(message)
+exit_json(changed, message)
}
class SudoRoleTasks {
+task_Record_role_begin_fingerprint()
+task_Record_role_success_fingerprint()
}
sr_fingerprint_module ..> AnsibleModule : uses
SudoRoleTasks ..> sr_fingerprint_module : calls
%% Details of run_module behavior
class run_module_behavior {
-sr_message str
-log_message str
+build_log_message(sr_message) str
+handle_check_mode(sr_message)
+write_to_syslog(log_message)
}
sr_fingerprint_module *-- run_module_behavior
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[citest] |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
sr_fingerprint._local_iso8601_no_microseconds, you calldatetime.datetime.now()twice in different branches; consider capturingnow = datetime.datetime.now()once and reusing it to avoid tiny inconsistencies and simplify the logic. - The journal check shell task runs
journalctltwice and chains multiplegreps; you could simplify and speed this up by invokingjournalctlonce and using Ansible’sregister+searchfilter (or a singlegrep -Epattern) to avoid duplicated processes and long shell pipelines. - The
sr_fingerprintmodule only logs and returnschanged=Falsewith no details; consider returning the composedlog_message(or at least the timestamp) inexit_jsonso callers or debuggers can see exactly what was emitted without re-reading syslog.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `sr_fingerprint._local_iso8601_no_microseconds`, you call `datetime.datetime.now()` twice in different branches; consider capturing `now = datetime.datetime.now()` once and reusing it to avoid tiny inconsistencies and simplify the logic.
- The journal check shell task runs `journalctl` twice and chains multiple `grep`s; you could simplify and speed this up by invoking `journalctl` once and using Ansible’s `register` + `search` filter (or a single `grep -E` pattern) to avoid duplicated processes and long shell pipelines.
- The `sr_fingerprint` module only logs and returns `changed=False` with no details; consider returning the composed `log_message` (or at least the timestamp) in `exit_json` so callers or debuggers can see exactly what was emitted without re-reading syslog.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #113 +/- ##
=======================================
Coverage ? 47.76%
=======================================
Files ? 2
Lines ? 381
Branches ? 0
=======================================
Hits ? 182
Misses ? 199
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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>
|
[citest] |
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
Introduce role fingerprint logging via a new Ansible module and validate its presence in system logs during test runs.
New Features:
Enhancements:
Documentation: