Add syslog_facility parameter handling with systemd.journal (#41078)

* Add syslog_facility parameter handling with systemd.journal

- Fixed issue #41072

Signed-off-by: Hideki Saito <saito@fgrep.org>
pull/41281/head
Hideki Saito 7 years ago committed by Toshio Kuratomi
parent 89cea78e30
commit d7df072b96

@ -0,0 +1,5 @@
---
bugfixes:
- Fixed runtime module to be able to handle syslog_facility properly
when python systemd module installed in a target system.
(https://github.com/ansible/ansible/pull/41078)

@ -54,6 +54,14 @@ Modules
Major changes in popular modules are detailed here Major changes in popular modules are detailed here
* The :ref:`DEFAULT_SYSLOG_FACILITY` configuration option tells Ansible modules to use a specific
`syslog facility <https://en.wikipedia.org/wiki/Syslog#Facility>`_ when logging information on all
managed machines. Due to a bug with older Ansible versions, this setting did not affect machines
using journald with the systemd Python bindings installed. On those machines, Ansible log
messages were sent to ``/var/log/messages``, even if you set :ref:`DEFAULT_SYSLOG_FACILITY`.
Ansible 2.7 fixes this bug, routing all Ansible log messages according to the value set for
:ref:`DEFAULT_SYSLOG_FACILITY`. If you have :ref:`DEFAULT_SYSLOG_FACILITY` configured, the
location of remote logs on systems which use journald may change.
Modules removed Modules removed

@ -2185,7 +2185,19 @@ class AnsibleModule(object):
for arg in log_args: for arg in log_args:
journal_args.append((arg.upper(), str(log_args[arg]))) journal_args.append((arg.upper(), str(log_args[arg])))
try: try:
journal.send(u"%s %s" % (module, journal_msg), **dict(journal_args)) if HAS_SYSLOG:
# If syslog_facility specified, it needs to convert
# from the facility name to the facility code, and
# set it as SYSLOG_FACILITY argument of journal.send()
facility = getattr(syslog,
self._syslog_facility,
syslog.LOG_USER) >> 3
journal.send(MESSAGE=u"%s %s" % (module, journal_msg),
SYSLOG_FACILITY=facility,
**dict(journal_args))
else:
journal.send(MESSAGE=u"%s %s" % (module, journal_msg),
**dict(journal_args))
except IOError: except IOError:
# fall back to syslog since logging to journal failed # fall back to syslog since logging to journal failed
self._log_to_syslog(syslog_msg) self._log_to_syslog(syslog_msg)

Loading…
Cancel
Save