From 2743f6c11735d4baed6b600d2820c92c5957cfa1 Mon Sep 17 00:00:00 2001 From: Emma Foley Date: Thu, 12 Sep 2024 17:49:51 +0100 Subject: [PATCH] [custom_logger] Make the output dir configurable (#148) 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. --- callback_plugins/custom_logger.py | 18 +++++++++++++++--- ci/ansible.cfg | 3 +++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/callback_plugins/custom_logger.py b/callback_plugins/custom_logger.py index 8e1c109e..19bc706f 100644 --- a/callback_plugins/custom_logger.py +++ b/callback_plugins/custom_logger.py @@ -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): @@ -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 @@ -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) \ No newline at end of file + self.log_task_result(host, 'skipped', task_name) diff --git a/ci/ansible.cfg b/ci/ansible.cfg index 3c9d90c0..ff9d632d 100644 --- a/ci/ansible.cfg +++ b/ci/ansible.cfg @@ -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