feat: add role fingerprints to syslog - #81
Merged
Conversation
Reviewer's GuideAdds a custom sr_fingerprint Ansible module to write standardized begin/success role fingerprints to syslog, wires it into the aide role lifecycle, and introduces a journal-based test plus ansible-lint sanity ignores to validate fingerprint logging without affecting idempotency. Sequence diagram for role fingerprint logging to syslogsequenceDiagram
actor User
participant AnsibleController
participant ManagedHost
participant sr_fingerprint_module as sr_fingerprint
participant Syslog
User->>AnsibleController: Run playbook with aide role
AnsibleController->>ManagedHost: Execute set_vars tasks
ManagedHost->>sr_fingerprint_module: sr_fingerprint sr_message="begin system_role:aide ..."
activate sr_fingerprint_module
sr_fingerprint_module->>sr_fingerprint_module: _local_iso8601_no_microseconds()
alt check_mode enabled
sr_fingerprint_module-->>ManagedHost: exit_json(changed=False, message="Check mode: message not logged - [...]")
else normal mode
sr_fingerprint_module->>Syslog: module.log("begin system_role:aide ... <timestamp>")
sr_fingerprint_module-->>ManagedHost: exit_json(changed=False)
end
deactivate sr_fingerprint_module
AnsibleController->>ManagedHost: Execute aide role main tasks
ManagedHost->>sr_fingerprint_module: sr_fingerprint sr_message="success system_role:aide ..."
activate sr_fingerprint_module
sr_fingerprint_module->>sr_fingerprint_module: _local_iso8601_no_microseconds()
alt check_mode enabled
sr_fingerprint_module-->>ManagedHost: exit_json(changed=False, message="Check mode: message not logged - [...]")
else normal mode
sr_fingerprint_module->>Syslog: module.log("success system_role:aide ... <timestamp>")
sr_fingerprint_module-->>ManagedHost: exit_json(changed=False)
end
deactivate sr_fingerprint_module
Updated class diagram for sr_fingerprint Ansible moduleclassDiagram
class sr_fingerprint_module {
+run_module()
+main()
-_local_iso8601_no_microseconds() str
}
class AnsibleModule {
+params dict
+check_mode bool
+log(msg)
+exit_json(**kwargs)
}
class datetime_module {
+datetime
+timezone
+now()
}
class time_module {
+strftime(format, t)
+localtime()
}
sr_fingerprint_module ..> AnsibleModule : uses
sr_fingerprint_module ..> datetime_module : uses
sr_fingerprint_module ..> time_module : fallback uses
Flow diagram for aide role lifecycle fingerprintsflowchart TD
Start["Start aide role execution"] --> SetVars["Run set_vars.yml"]
SetVars --> BeginFingerprint["Task: Record role begin fingerprint (sr_fingerprint)"]
BeginFingerprint --> AideTasks["Run main.yml aide tasks"]
AideTasks --> SuccessFingerprint["Task: Record role success fingerprint (sr_fingerprint)"]
SuccessFingerprint --> End["End aide role execution"]
subgraph FingerprintFormat["Fingerprint message format"]
BeginMsg["begin system_role:aide ansible_version=<version> <distro>-<version> <timestamp>"]
SuccessMsg["success system_role:aide ansible_version=<version> <distro>-<version> <timestamp>"]
end
BeginFingerprint -. writes .-> BeginMsg
SuccessFingerprint -. writes .-> SuccessMsg
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 fingerprint message strings (
begin system_role:aide/success system_role:aide) are hard-coded in multiple tasks; consider centralizing the role identifier in a variable or fact so it doesn’t need to be updated in several places if the role name or convention changes. - The test that inspects
journalctlassumes a systemd-based system and a working journal; you may want to guard this task with a condition likewhen: ansible_service_mgr == 'systemd'to avoid failures on non-systemd targets. - The module treats check mode as a no-op and exits without logging; if fingerprints are expected during dry-runs as well, consider either logging even in check mode or adding an option to control this behavior explicitly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The fingerprint message strings (`begin system_role:aide` / `success system_role:aide`) are hard-coded in multiple tasks; consider centralizing the role identifier in a variable or fact so it doesn’t need to be updated in several places if the role name or convention changes.
- The test that inspects `journalctl` assumes a systemd-based system and a working journal; you may want to guard this task with a condition like `when: ansible_service_mgr == 'systemd'` to avoid failures on non-systemd targets.
- The module treats check mode as a no-op and exits without logging; if fingerprints are expected during dry-runs as well, consider either logging even in check mode or adding an option to control this behavior explicitly.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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>
Contributor
Author
|
[citest] |
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 aide system role and verify it via tests.
New Features:
Tests: