feat: add role fingerprints to syslog#232
Merged
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 GuideAdds a new Ansible module Sequence diagram for role fingerprint logging to syslogsequenceDiagram
actor Admin
participant AnsibleController
participant Role_nbde_server
participant Module_sr_fingerprint
participant SyslogService
Admin->>AnsibleController: Run playbook using nbde_server role
AnsibleController->>Role_nbde_server: Execute tasks/set_vars.yml
Role_nbde_server->>Module_sr_fingerprint: Task Record_role_begin_fingerprint
Module_sr_fingerprint->>Module_sr_fingerprint: _local_iso8601_no_microseconds
alt check_mode_enabled
Module_sr_fingerprint-->>Role_nbde_server: exit_json changed=false message=Check_mode_message
else normal_mode
Module_sr_fingerprint->>SyslogService: module.log(sr_message + timestamp)
Module_sr_fingerprint-->>Role_nbde_server: exit_json changed=false
end
AnsibleController->>Role_nbde_server: Execute provider specific tasks main_nbde_server_provider.yml
AnsibleController->>Role_nbde_server: Execute tasks/main.yml
Role_nbde_server->>Module_sr_fingerprint: Task Record_role_success_fingerprint
Module_sr_fingerprint->>Module_sr_fingerprint: _local_iso8601_no_microseconds
alt check_mode_enabled
Module_sr_fingerprint-->>Role_nbde_server: exit_json changed=false message=Check_mode_message
else normal_mode
Module_sr_fingerprint->>SyslogService: module.log(sr_message + timestamp)
Module_sr_fingerprint-->>Role_nbde_server: exit_json changed=false
end
Role_nbde_server-->>AnsibleController: Role execution finished
AnsibleController-->>Admin: Report role completed successfully
Class diagram for the new sr_fingerprint Ansible moduleclassDiagram
class Module_sr_fingerprint {
+run_module()
+main()
+_local_iso8601_no_microseconds() str
}
class AnsibleModule {
+dict params
+bool check_mode
+log(message)
+exit_json(changed, message)
}
class datetime {
+datetime now()
+timezone utc
}
class time_module {
+str strftime(format, tuple)
+tuple localtime()
}
Module_sr_fingerprint ..> AnsibleModule : uses
Module_sr_fingerprint ..> datetime : uses
Module_sr_fingerprint ..> time_module : fallback_implementation
Module_sr_fingerprint : run_module()
Module_sr_fingerprint : main()
Module_sr_fingerprint : _local_iso8601_no_microseconds()
AnsibleModule : params
AnsibleModule : check_mode
AnsibleModule : log(message)
AnsibleModule : exit_json(changed, message)
Flow diagram for nbde_server role with begin and success fingerprintsflowchart TD
Start[Start nbde_server role] --> GatherFacts[Gather required ansible_facts]
GatherFacts --> CheckMissingFacts{Missing required facts?}
CheckMissingFacts -->|Yes| LoadFacts[Load missing facts]
CheckMissingFacts -->|No| AfterFacts[Facts ready]
LoadFacts --> AfterFacts
AfterFacts --> BeginFingerprint[Call sr_fingerprint with begin system_role_nbde_server]
BeginFingerprint --> CheckModeBegin{Ansible check mode?}
CheckModeBegin -->|Yes| SkipLogBegin[Skip syslog write, exit_json changed=false]
CheckModeBegin -->|No| LogBegin[Write begin fingerprint to syslog via module.log]
SkipLogBegin --> ProviderTasks
LogBegin --> ProviderTasks[Include provider tasks main_nbde_server_provider.yml]
ProviderTasks --> SuccessFingerprint[Call sr_fingerprint with success system_role_nbde_server]
SuccessFingerprint --> CheckModeSuccess{Ansible check mode?}
CheckModeSuccess -->|Yes| SkipLogSuccess[Skip syslog write, exit_json changed=false]
CheckModeSuccess -->|No| LogSuccess[Write success fingerprint to syslog via module.log]
SkipLogSuccess --> End[End nbde_server role]
LogSuccess --> End
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 left some high level feedback:
- The journal-based test assumes both /dev/log and journalctl are available; consider adding an explicit guard for journalctl’s presence (e.g., a
journalctl --versionprobe withfailed_when: false) so the test cleanly skips or degrades on non-systemd or minimal environments. - In the
sr_fingerprintmodule, it could be useful to return the constructed log message (and timestamp) inexit_json(e.g.,logged_message/logged_at) so callers and tests can introspect what was emitted without having to rely solely on external log inspection.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The journal-based test assumes both /dev/log and journalctl are available; consider adding an explicit guard for journalctl’s presence (e.g., a `journalctl --version` probe with `failed_when: false`) so the test cleanly skips or degrades on non-systemd or minimal environments.
- In the `sr_fingerprint` module, it could be useful to return the constructed log message (and timestamp) in `exit_json` (e.g., `logged_message`/`logged_at`) so callers and tests can introspect what was emitted without having to rely solely on external log inspection.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 syslog fingerprinting for the nbde_server role and verify it via journal-based tests.
New Features:
Tests:
Chores: