feat: add role fingerprints to syslog#191
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 sr_fingerprint to log role lifecycle fingerprints to syslog and wires it into the crypto_policies role along with a journal-based test, plus supporting sanity ignore files and test role library path. Sequence diagram for role lifecycle fingerprint loggingsequenceDiagram
actor Admin
participant AnsibleController
participant CryptoPoliciesRole
participant SrFingerprintModule as sr_fingerprint
participant Syslog
Admin->>AnsibleController: Run playbook with crypto_policies role
AnsibleController->>CryptoPoliciesRole: Start role execution
Note over CryptoPoliciesRole: set_vars.yml
CryptoPoliciesRole->>SrFingerprintModule: begin fingerprint (sr_message)
SrFingerprintModule->>SrFingerprintModule: _local_iso8601_no_microseconds()
SrFingerprintModule->>Syslog: module.log("begin system_role:crypto_policies ... <timestamp>")
CryptoPoliciesRole->>CryptoPoliciesRole: Apply crypto policies tasks
Note over CryptoPoliciesRole: main.yml
CryptoPoliciesRole->>SrFingerprintModule: success fingerprint (sr_message)
SrFingerprintModule->>SrFingerprintModule: _local_iso8601_no_microseconds()
SrFingerprintModule->>Syslog: module.log("success system_role:crypto_policies ... <timestamp>")
Syslog-->>Admin: Logs visible via journald/log aggregator
Class diagram for the new sr_fingerprint Ansible moduleclassDiagram
class sr_fingerprint_module {
+run_module()
+main()
-_local_iso8601_no_microseconds() datetime
}
class AnsibleModule {
+params dict
+check_mode bool
+log(message)
+exit_json(changed, message)
}
sr_fingerprint_module ..> AnsibleModule : uses
class _local_iso8601_no_microseconds_helper {
+_local_iso8601_no_microseconds() string
}
sr_fingerprint_module ..> _local_iso8601_no_microseconds_helper : calls
class Role_crypto_policies_tasks {
+set_vars_yml()
+main_yml()
}
class Task_Record_role_begin_fingerprint {
+sr_message string
}
class Task_Record_role_success_fingerprint {
+sr_message string
}
Role_crypto_policies_tasks o-- Task_Record_role_begin_fingerprint : includes
Role_crypto_policies_tasks o-- Task_Record_role_success_fingerprint : includes
Task_Record_role_begin_fingerprint ..> sr_fingerprint_module : invokes
Task_Record_role_success_fingerprint ..> sr_fingerprint_module : invokes
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The journal-based test currently assumes the syslog format will contain
sr_fingerprintin the log line; relying on Ansible’s internal log format is brittle across versions, so it would be safer to grep only for the stable message content (e.g.begin system_role:crypto_policies/success system_role:crypto_policies) rather than the module name. - The
sr_fingerprintmodule skips logging in check mode, which means role executions with--checkwon’t leave any fingerprints; if the goal is to trace all role invocations, consider logging even in check mode while still returningchanged=False. - The shell-based journalctl check runs two nearly identical pipelines and filters out
" Invoked with"lines withgrep -v, which may accidentally drop other relevant lines; you could simplify and harden this by using a singlejournalctlinvocation and more precise grep patterns anchored on the fingerprint message structure.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The journal-based test currently assumes the syslog format will contain `sr_fingerprint` in the log line; relying on Ansible’s internal log format is brittle across versions, so it would be safer to grep only for the stable message content (e.g. `begin system_role:crypto_policies` / `success system_role:crypto_policies`) rather than the module name.
- The `sr_fingerprint` module skips logging in check mode, which means role executions with `--check` won’t leave any fingerprints; if the goal is to trace all role invocations, consider logging even in check mode while still returning `changed=False`.
- The shell-based journalctl check runs two nearly identical pipelines and filters out `" Invoked with"` lines with `grep -v`, which may accidentally drop other relevant lines; you could simplify and harden this by using a single `journalctl` invocation and more precise grep patterns anchored on the fingerprint message structure.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 a role-internal fingerprint mechanism that logs begin and success markers for the crypto_policies role to syslog and verify them in tests.
New Features:
Tests:
Chores: