From 189b210f5adfa2410328914d72300a502d9f1c68 Mon Sep 17 00:00:00 2001 From: Stephen Fromm Date: Wed, 24 Apr 2013 15:00:47 -0700 Subject: [PATCH] Catch exception when logging to systemd journal fails systemd journal will throw IOError exception when journal.sendv() fails. This catches that and falls back to syslog. See issue #2773. --- lib/ansible/module_common.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_common.py b/lib/ansible/module_common.py index 5c92abfd63..c5bb9d46b4 100644 --- a/lib/ansible/module_common.py +++ b/lib/ansible/module_common.py @@ -692,7 +692,12 @@ class AnsibleModule(object): journal_args.append("MODULE=%s" % os.path.basename(__file__)) for arg in log_args: journal_args.append(arg.upper() + "=" + str(log_args[arg])) - journal.sendv(*journal_args) + try: + journal.sendv(*journal_args) + except IOError, e: + # fall back to syslog since logging to journal failed + syslog.openlog(module, 0, syslog.LOG_USER) + syslog.syslog(syslog.LOG_NOTICE, msg) else: syslog.openlog(module, 0, syslog.LOG_USER) syslog.syslog(syslog.LOG_NOTICE, msg)