Fix crash in py3: 'TypeError: a bytes-like object is required, not 'str' (#37504)

* Fix crash in py3: 'TypeError: a bytes-like object is required, not 'str'

Fixes #37387

* Review applied https://github.com/ansible/ansible/pull/37504#pullrequestreview-104799823
pull/37670/head
alu 7 years ago committed by Toshio Kuratomi
parent 8c4f349743
commit b7aa41b9b9

@ -141,6 +141,7 @@ import re
import tempfile import tempfile
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_bytes
def lineDict(line): def lineDict(line):
@ -321,7 +322,7 @@ def write_changes(module, lines, dest):
tmpfd, tmpfile = tempfile.mkstemp() tmpfd, tmpfile = tempfile.mkstemp()
f = os.fdopen(tmpfd, 'wb') f = os.fdopen(tmpfd, 'wb')
f.writelines(lines) f.writelines(to_bytes(lines, errors='surrogate_or_strict'))
f.close() f.close()
module.atomic_move(tmpfile, os.path.realpath(dest)) module.atomic_move(tmpfile, os.path.realpath(dest))

Loading…
Cancel
Save