Skip to content

Commit

Permalink
[custom_logger] Make the output dir configurable (#148)
Browse files Browse the repository at this point in the history
Allow configuration via the env var CUSTOM_PLUGIN_OUTPUT_DIR or the ini
file using the "output_dir" option in the "custom_logger" section.

NOTE: For paths, a leading "/" is needed when using env vars so that the
path is read as an absolute path.
  • Loading branch information
elfiesmelfie authored Sep 12, 2024
1 parent bfaac63 commit 2743f6c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
18 changes: 15 additions & 3 deletions callback_plugins/custom_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
- Log file names:
- test_run_result.out
- summary_results.log
options:
output_dir:
description: todo
ini:
- section: custom_logger
key: output_dir
env:
- name: CUSTOM_LOGGER_OUTPUT_DIR
default: "."
type: path
'''

class CallbackModule(CallbackBase):
Expand All @@ -31,9 +41,11 @@ class CallbackModule(CallbackBase):

def __init__(self):
super(CallbackModule, self).__init__()
self.output_dir = os.path.expanduser("~/")
self.results = {}
self.set_options()

self.output_dir = self.get_option('output_dir')
self.results = {}

def playbook_on_stats(self, stats):
#Log results for each host
hosts= stats.processed
Expand Down Expand Up @@ -89,4 +101,4 @@ def v2_runner_on_failed(self, result, ignore_errors=False):
def v2_runner_on_skipped(self, result):
host = result._host.get_name()
task_name = result._task.get_name()
self.log_task_result(host, 'skipped', task_name)
self.log_task_result(host, 'skipped', task_name)
3 changes: 3 additions & 0 deletions ci/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ callbacks_enabled = custom_logger
callback_plugins = ../callback_plugins
# additional paths to search for roles
roles_path = ../roles:/usr/share/ansible/roles:/etc/ansible/roles:~/.ansible/roles:../../ci-framework/roles

[custom_logger]
output_dir = /$HOME

0 comments on commit 2743f6c

Please sign in to comment.