diff --git a/ansible_mitogen/connection.py b/ansible_mitogen/connection.py index e017608e..f14576ad 100644 --- a/ansible_mitogen/connection.py +++ b/ansible_mitogen/connection.py @@ -914,9 +914,9 @@ class Connection(ansible.plugins.connection.ConnectionBase): emulate_tty=emulate_tty, ) - stderr += 'Shared connection to %s closed.%s' % ( - self._play_context.remote_addr, - ('\r\n' if emulate_tty else '\n'), + stderr += b'Shared connection to %s closed.%s' % ( + self._play_context.remote_addr.encode(), + (b'\r\n' if emulate_tty else b'\n'), ) return rc, stdout, stderr diff --git a/ansible_mitogen/target.py b/ansible_mitogen/target.py index 0e74f960..83069422 100644 --- a/ansible_mitogen/target.py +++ b/ansible_mitogen/target.py @@ -541,7 +541,7 @@ def exec_args(args, in_data='', chdir=None, shell=None, emulate_tty=False): if emulate_tty: stdout = stdout.replace(b'\n', b'\r\n') - return proc.returncode, stdout, stderr or '' + return proc.returncode, stdout, stderr or b'' def exec_command(cmd, in_data='', chdir=None, shell=None, emulate_tty=False): diff --git a/tests/ansible/integration/connection/exec_command.yml b/tests/ansible/integration/connection/exec_command.yml index 6a632961..105505d1 100644 --- a/tests/ansible/integration/connection/exec_command.yml +++ b/tests/ansible/integration/connection/exec_command.yml @@ -15,5 +15,5 @@ - assert: that: - out.result[0] == 0 - - out.result[1] == "hello, world\r\n" - - out.result[2].startswith("Shared connection to ") + - out.result[1].decode() == "hello, world\r\n" + - out.result[2].decode().startswith("Shared connection to ")