diff --git a/changelogs/fragments/4223-syslog-json-skip-syslog-option.yml b/changelogs/fragments/4223-syslog-json-skip-syslog-option.yml new file mode 100644 index 0000000000..4850a3a967 --- /dev/null +++ b/changelogs/fragments/4223-syslog-json-skip-syslog-option.yml @@ -0,0 +1,2 @@ +minor_changes: + - syslog_json - add option to skip logging of ``gather_facts`` playbook tasks; use v2 callback API (https://github.com/ansible-collections/community.general/pull/4223). diff --git a/plugins/callback/syslog_json.py b/plugins/callback/syslog_json.py index f4865f2a26..0d71545495 100644 --- a/plugins/callback/syslog_json.py +++ b/plugins/callback/syslog_json.py @@ -41,6 +41,16 @@ DOCUMENTATION = ''' ini: - section: callback_syslog_json key: syslog_facility + setup: + description: Log setup tasks. + env: + - name: ANSIBLE_SYSLOG_SETUP + type: bool + default: true + ini: + - section: callback_syslog_json + key: syslog_setup + version_added: 4.5.0 ''' import os @@ -86,23 +96,36 @@ class CallbackModule(CallbackBase): self.logger.addHandler(self.handler) self.hostname = socket.gethostname() - def runner_on_failed(self, host, res, ignore_errors=False): + def v2_runner_on_failed(self, result, ignore_errors=False): + res = result._result + host = result._host.get_name() self.logger.error('%s ansible-command: task execution FAILED; host: %s; message: %s', self.hostname, host, self._dump_results(res)) - def runner_on_ok(self, host, res): - self.logger.info('%s ansible-command: task execution OK; host: %s; message: %s', self.hostname, host, self._dump_results(res)) + def v2_runner_on_ok(self, result): + res = result._result + host = result._host.get_name() + if result._task.action != "gather_facts" or self.get_option("setup"): + self.logger.info('%s ansible-command: task execution OK; host: %s; message: %s', self.hostname, host, self._dump_results(res)) - def runner_on_skipped(self, host, item=None): + def v2_runner_on_skipped(self, result): + host = result._host.get_name() self.logger.info('%s ansible-command: task execution SKIPPED; host: %s; message: %s', self.hostname, host, 'skipped') - def runner_on_unreachable(self, host, res): + def v2_runner_on_unreachable(self, result): + res = result._result + host = result._host.get_name() self.logger.error('%s ansible-command: task execution UNREACHABLE; host: %s; message: %s', self.hostname, host, self._dump_results(res)) - def runner_on_async_failed(self, host, res, jid): + def v2_runner_on_async_failed(self, result): + res = result._result + host = result._host.get_name() + jid = result._result.get('ansible_job_id') self.logger.error('%s ansible-command: task execution FAILED; host: %s; message: %s', self.hostname, host, self._dump_results(res)) - def playbook_on_import_for_host(self, host, imported_file): + def v2_playbook_on_import_for_host(self, result, imported_file): + host = result._host.get_name() self.logger.info('%s ansible-command: playbook IMPORTED; host: %s; message: imported file %s', self.hostname, host, imported_file) - def playbook_on_not_import_for_host(self, host, missing_file): + def v2_playbook_on_not_import_for_host(self, result, missing_file): + host = result._host.get_name() self.logger.info('%s ansible-command: playbook NOT IMPORTED; host: %s; message: missing file %s', self.hostname, host, missing_file)