-
Notifications
You must be signed in to change notification settings - Fork 12
feat: add role fingerprints to syslog #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| plugins/modules/sr_fingerprint.py validate-modules:missing-gplv3-license |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| plugins/modules/sr_fingerprint.py validate-modules:missing-gplv3-license |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| plugins/modules/sr_fingerprint.py validate-modules:missing-gplv3-license |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| plugins/modules/sr_fingerprint.py validate-modules:missing-gplv3-license |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| plugins/modules/sr_fingerprint.py validate-modules:missing-gplv3-license |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| plugins/modules/sr_fingerprint.py validate-modules:missing-gplv3-license |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| plugins/modules/sr_fingerprint.py validate-modules:missing-gplv3-license |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| plugins/modules/sr_fingerprint.py validate-modules:missing-gplv3-license |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/usr/bin/python | ||
|
|
||
| from __future__ import absolute_import, division, print_function | ||
|
|
||
| __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. | ||
| - Intended for role-internal or diagnostic use. | ||
| author: Rich Megginson (@richm) | ||
| options: | ||
| sr_message: | ||
| description: Text to record in syslog. | ||
| type: str | ||
| required: true | ||
| """ | ||
|
|
||
| EXAMPLES = """ | ||
| - name: Record a fingerprint message in syslog | ||
| sr_fingerprint: | ||
| sr_message: "system_role:ROLENAME" | ||
| """ | ||
|
|
||
| RETURN = r""" # """ | ||
|
|
||
| from ansible.module_utils.basic import AnsibleModule | ||
|
|
||
| import datetime | ||
|
|
||
|
|
||
| def _local_iso8601_no_microseconds(): | ||
| """System local wall clock with local tz offset, ISO 8601, seconds only.""" | ||
| try: | ||
| utc = datetime.timezone.utc | ||
| except AttributeError: | ||
| import time | ||
|
|
||
| return time.strftime("%Y-%m-%dT%H:%M:%S%z", time.localtime()) | ||
| # Prefer the local clock interpreted in the system timezone (not UTC displayed). | ||
| now = datetime.datetime.now() | ||
| astimezone = getattr(now, "astimezone", None) | ||
| if astimezone is not None: | ||
| try: | ||
| return astimezone().replace(microsecond=0).isoformat() | ||
| except (OSError, TypeError, ValueError): | ||
| pass | ||
| return datetime.datetime.now(utc).astimezone().replace(microsecond=0).isoformat() | ||
|
|
||
|
|
||
| def run_module(): | ||
| module_args = dict( | ||
| sr_message=dict(type="str", required=True), | ||
| ) | ||
|
|
||
| module = AnsibleModule( | ||
| argument_spec=module_args, | ||
| supports_check_mode=True, | ||
| ) | ||
|
|
||
| log_message = "%s %s" % ( | ||
| module.params["sr_message"], | ||
| _local_iso8601_no_microseconds(), | ||
| ) | ||
|
|
||
| if module.check_mode: | ||
| module.exit_json( | ||
| changed=False, | ||
| message="Check mode: message not logged - [%s]" % log_message, | ||
| ) | ||
|
|
||
| module.log(log_message) | ||
|
|
||
| # we don't actually change anything, so we're not changed - writing a log message | ||
| # is not considered a change | ||
| # also, we don't want to report changed every time the role runs | ||
| module.exit_json(changed=False) | ||
|
|
||
|
|
||
| def main(): | ||
| run_module() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../library |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): RETURN spec is not valid YAML and may break ansible-doc / sanity checks.
Using
RETURN = r""" # """produces invalid YAML for Ansible’s docs parser and can causeansible-docand sanity checks to fail (or require suppression via ignore files). Either provide a minimal valid YAML structure (e.g. an empty mapping) or drop theRETURNvariable entirely if you don’t need documented return fields, so tooling continues to work without relying on ignores.