feat: add role fingerprints to syslog#13
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 GuideAdds a new sr_fingerprint Ansible module to log role start/success fingerprints to syslog and wires it into the trustee_server role with accompanying journal-based tests and Ansible sanity ignores. Sequence diagram for sr_fingerprint module logging to syslogsequenceDiagram
actor Operator
participant AnsibleController
participant sr_fingerprint_module
participant AnsibleModule
participant Syslog
Operator->>AnsibleController: Run trustee_server role
AnsibleController->>sr_fingerprint_module: Invoke sr_fingerprint sr_message
activate sr_fingerprint_module
sr_fingerprint_module->>sr_fingerprint_module: _local_iso8601_no_microseconds()
sr_fingerprint_module->>AnsibleModule: Create instance with argument_spec and supports_check_mode
activate AnsibleModule
alt Check mode enabled
sr_fingerprint_module->>AnsibleModule: exit_json(changed=False, message="Check mode: message not logged ...")
else Normal execution
sr_fingerprint_module->>AnsibleModule: module.log(log_message)
AnsibleModule->>Syslog: Write log_message
sr_fingerprint_module->>AnsibleModule: exit_json(changed=False)
end
deactivate AnsibleModule
deactivate sr_fingerprint_module
AnsibleController-->>Operator: Report role completion
Class diagram for sr_fingerprint Ansible moduleclassDiagram
class sr_fingerprint_module {
<<module>>
+_local_iso8601_no_microseconds() str
+run_module() void
+main() void
}
class AnsibleModule {
<<external>>
+log(msg)
+exit_json(**kwargs)
}
sr_fingerprint_module ..> AnsibleModule : uses
Flow diagram for trustee_server role begin/success fingerprintsflowchart TD
A[Start trustee_server role] --> B[set_vars.yml]
B --> C[Task: Record role begin fingerprint
sr_fingerprint sr_message='begin system_role:trustee_server ...']
C --> D[Other set_vars tasks
Determine if system is ostree, set flags, etc.]
D --> E[tasks/main.yml]
E --> F[Main role tasks
trustee_server_secret_registration, trustee_server_trustee, etc.]
F --> G[Task: Record role success fingerprint
sr_fingerprint sr_message='success system_role:trustee_server ...']
G --> H[End trustee_server role]
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 found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="library/sr_fingerprint.py" line_range="7-10" />
<code_context>
+
+__metaclass__ = type
+
+DOCUMENTATION = """
+---
+module: sr_fingerprint
+short_description: Write a message string to syslog using Ansible C(module.log) function.
+description:
+ - Writes the given string to the system log using Ansible C(module.log) function.
</code_context>
<issue_to_address>
**issue:** The documentation claims syslog logging, but `module.log` doesn’t always map directly to syslog across all connections.
`module.log` writes to the Ansible log, which may or may not end up in syslog depending on controller configuration and callbacks. Relying on this to always appear in the system syslog is therefore inaccurate. Please update the wording to either refer to the Ansible log, or clearly state under which configurations the messages will appear in syslog.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| DOCUMENTATION = """ | ||
| --- | ||
| module: sr_fingerprint | ||
| short_description: Write a message string to syslog using Ansible C(module.log) function. |
There was a problem hiding this comment.
issue: The documentation claims syslog logging, but module.log doesn’t always map directly to syslog across all connections.
module.log writes to the Ansible log, which may or may not end up in syslog depending on controller configuration and callbacks. Relying on this to always appear in the system syslog is therefore inaccurate. Please update the wording to either refer to the Ansible log, or clearly state under which configurations the messages will appear in syslog.
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 custom Ansible module and role hooks to write start and success fingerprints for the trustee_server role to syslog, and validate them via tests.
New Features:
CI:
Tests: