From b7aa41b9b937df7af6afa1404be5c9c3d85f0948 Mon Sep 17 00:00:00 2001 From: alu Date: Wed, 21 Mar 2018 06:33:14 +0900 Subject: [PATCH] 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 --- lib/ansible/modules/system/interfaces_file.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/system/interfaces_file.py b/lib/ansible/modules/system/interfaces_file.py index 41cda40c6e7..27b084ae585 100755 --- a/lib/ansible/modules/system/interfaces_file.py +++ b/lib/ansible/modules/system/interfaces_file.py @@ -141,6 +141,7 @@ import re import tempfile from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_bytes def lineDict(line): @@ -321,7 +322,7 @@ def write_changes(module, lines, dest): tmpfd, tmpfile = tempfile.mkstemp() f = os.fdopen(tmpfd, 'wb') - f.writelines(lines) + f.writelines(to_bytes(lines, errors='surrogate_or_strict')) f.close() module.atomic_move(tmpfile, os.path.realpath(dest))