Convert to byte strings to avoid UnicodeErrors

Fixes #12488
This commit is contained in:
Toshio Kuratomi 2015-09-23 15:23:29 -07:00
parent de18bcb95f
commit 5d3d9cfe0d
3 changed files with 29 additions and 18 deletions

View file

@ -19,6 +19,7 @@ import os
import time
import json
from ansible.utils.unicode import to_bytes
from ansible.plugins.callback import CallbackBase
# NOTE: in Ansible 1.2 or later general logging is available without
@ -60,9 +61,10 @@ class CallbackModule(CallbackBase):
path = os.path.join("/var/log/ansible/hosts", host)
now = time.strftime(self.TIME_FORMAT, time.localtime())
fd = open(path, "a")
fd.write(self.MSG_FORMAT % dict(now=now, category=category, data=data))
fd.close()
msg = to_bytes(self.MSG_FORMAT % dict(now=now, category=category, data=data))
with open(path, "ab") as fd:
fd.write(msg)
def runner_on_failed(self, host, res, ignore_errors=False):
self.log(host, 'FAILED', res)