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()