mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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>
This commit is contained in:
parent
89cea78e30
commit
d7df072b96
3 changed files with 26 additions and 1 deletions
5
changelogs/fragments/syslog_facility-for-journald.yml
Normal file
5
changelogs/fragments/syslog_facility-for-journald.yml
Normal file
|
@ -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
|
||||
|
||||
* 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
|
||||
|
|
|
@ -2185,7 +2185,19 @@ class AnsibleModule(object):
|
|||
for arg in log_args:
|
||||
journal_args.append((arg.upper(), str(log_args[arg])))
|
||||
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:
|
||||
# fall back to syslog since logging to journal failed
|
||||
self._log_to_syslog(syslog_msg)
|
||||
|
|
Loading…
Reference in a new issue