feat: add role fingerprints to syslog#29
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 sr_fingerprint Ansible module to write structured role fingerprint messages to syslog, wires it into the trustee_client role at begin/success points, and extends the default test playbook to validate the fingerprints via journalctl when /dev/log is available while updating sanity ignore files for the custom module across supported Ansible versions. Sequence diagram for trustee_client role fingerprints to syslogsequenceDiagram
actor User
participant AnsibleController
participant AnsibleEngine
participant TrusteeClientRole
participant SrFingerprintModule
participant Syslog
User->>AnsibleController: run playbook with trustee_client role
AnsibleController->>AnsibleEngine: execute playbook
AnsibleEngine->>TrusteeClientRole: start role tasks
Note over TrusteeClientRole: Begin fingerprint task
TrusteeClientRole->>SrFingerprintModule: sr_fingerprint sr_message=begin system_role:trustee_client
SrFingerprintModule->>SrFingerprintModule: build log_message with timestamp
alt check_mode
SrFingerprintModule-->>AnsibleEngine: exit changed=false, message=Check mode
else normal_mode
SrFingerprintModule->>Syslog: module.log(log_message)
SrFingerprintModule-->>AnsibleEngine: exit changed=false
end
Note over TrusteeClientRole: Main role tasks (e.g. encrypt_disk)
TrusteeClientRole->>TrusteeClientRole: perform trustee_client tasks
Note over TrusteeClientRole: Success fingerprint task
TrusteeClientRole->>SrFingerprintModule: sr_fingerprint sr_message=success system_role:trustee_client
SrFingerprintModule->>SrFingerprintModule: build log_message with timestamp
alt check_mode
SrFingerprintModule-->>AnsibleEngine: exit changed=false, message=Check mode
else normal_mode
SrFingerprintModule->>Syslog: module.log(log_message)
SrFingerprintModule-->>AnsibleEngine: exit changed=false
end
AnsibleEngine-->>AnsibleController: role completed
User->>Syslog: inspect fingerprints via journalctl or syslog tools
Class diagram for sr_fingerprint Ansible moduleclassDiagram
class SrFingerprintModuleFile {
+_local_iso8601_no_microseconds() str
+run_module() void
+main() void
}
class AnsibleModule {
+params dict
+check_mode bool
+log(message str) void
+exit_json(**kwargs) void
}
class DatetimeModule {
+datetime
+timezone
+now() datetime
}
class TimeModule {
+strftime(format str, struct_time)
+localtime() struct_time
}
SrFingerprintModuleFile ..> AnsibleModule : uses
SrFingerprintModuleFile ..> DatetimeModule : uses
SrFingerprintModuleFile ..> TimeModule : legacy fallback
class SrFingerprintInvocation {
+sr_message str
+log_message str
}
SrFingerprintModuleFile ..> SrFingerprintInvocation : constructs
class TrusteeClientRoleTasks {
+Record_role_begin_fingerprint
+Record_role_success_fingerprint
}
TrusteeClientRoleTasks ..> SrFingerprintModuleFile : calls sr_fingerprint
class SyslogService {
+receive_log(message str) void
}
AnsibleModule ..> SyslogService : module.log forwards to syslog
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Collaborator
Author
|
[citest] |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
sr_fingerprintmodule currently accepts any string, including empty/whitespace-only values, assr_message; consider adding simple validation/normalization (e.g., strip and fail on empty) to avoid writing useless entries to syslog. - The journal check in
tests_default.ymluses a long shell pipeline withjournalctl | grep -v | grep ...; you could improve robustness and readability by usingjournalctl --grep(or separatecommandinvocations with-q) andfailed_whenon the return code instead of hand-rolledset -eo pipefaillogic.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `sr_fingerprint` module currently accepts any string, including empty/whitespace-only values, as `sr_message`; consider adding simple validation/normalization (e.g., strip and fail on empty) to avoid writing useless entries to syslog.
- The journal check in `tests_default.yml` uses a long shell pipeline with `journalctl | grep -v | grep ...`; you could improve robustness and readability by using `journalctl --grep` (or separate `command` invocations with `-q`) and `failed_when` on the return code instead of hand-rolled `set -eo pipefail` logic.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 to the trustee_client role and verify it via system journal tests.
New Features:
Tests:
Chores: