From 2ef7759be1515b82495217e718152735ed589f33 Mon Sep 17 00:00:00 2001 From: Paddy Newman Date: Fri, 31 May 2019 19:29:15 +0100 Subject: [PATCH] =?UTF-8?q?Allow=20syslog=5Fjson=20callback=20options=20to?= =?UTF-8?q?=20be=20set=20in=20an=20Ansible=20configurat=E2=80=A6=20(#57232?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Allow syslog_json callback options to be set in an Ansible configuration file. The syslog_json documentation says that it supports options via an Ansible configuration file. In fact, they can only be specified via environment variables. I've updated the module to use the standard "get_options" handling which means that it can now support options via environment variables *or* the configuration file. Options can be set in the configuration file as follows: ``` callback_whitelist = syslog_json [callback_syslog_json] syslog_server = localhost syslog_port = 514 syslog_facility = user ``` * Use the original, documented, names for the modules options. In the documentation text change syslog_server to server, syslog_port to port and syslog_facility to facility. * Add an item to the changelog. * Update 57232-syslog-json-configuration-options.yml Fix a YAML syntax error / typo. --- .../57232-syslog-json-configuration-options.yml | 2 ++ lib/ansible/plugins/callback/syslog_json.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/57232-syslog-json-configuration-options.yml diff --git a/changelogs/fragments/57232-syslog-json-configuration-options.yml b/changelogs/fragments/57232-syslog-json-configuration-options.yml new file mode 100644 index 00000000000..7304f3d8588 --- /dev/null +++ b/changelogs/fragments/57232-syslog-json-configuration-options.yml @@ -0,0 +1,2 @@ +minor_changes: +- "syslog_json - Allow configuration of the syslog_json plugin via an Ansible configuration file." diff --git a/lib/ansible/plugins/callback/syslog_json.py b/lib/ansible/plugins/callback/syslog_json.py index 13d73829194..07400c8e4cd 100644 --- a/lib/ansible/plugins/callback/syslog_json.py +++ b/lib/ansible/plugins/callback/syslog_json.py @@ -14,7 +14,7 @@ DOCUMENTATION = ''' version_added: "1.9" description: - This plugin logs ansible-playbook and ansible runs to a syslog server in JSON format - - Before 2.4 only environment variables were available for configuration + - Before 2.9 only environment variables were available for configuration options: server: description: syslog server that will receive the event @@ -67,12 +67,18 @@ class CallbackModule(CallbackBase): super(CallbackModule, self).__init__() + self.set_options() + + syslog_host = self.get_option("server") + syslog_port = int(self.get_option("port")) + syslog_facility = self.get_option("facility") + self.logger = logging.getLogger('ansible logger') self.logger.setLevel(logging.DEBUG) self.handler = logging.handlers.SysLogHandler( - address=(os.getenv('SYSLOG_SERVER', 'localhost'), int(os.getenv('SYSLOG_PORT', 514))), - facility=os.getenv('SYSLOG_FACILITY', logging.handlers.SysLogHandler.LOG_USER) + address=(syslog_host, syslog_port), + facility=syslog_facility ) self.logger.addHandler(self.handler) self.hostname = socket.gethostname()