mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Use to_bytes to avoid tracebacks when passed a byte str instead of a unicode string
Fixes #11198
This commit is contained in:
parent
bbfc982dd5
commit
e88a9e943c
1 changed files with 5 additions and 2 deletions
|
@ -45,6 +45,7 @@ from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNo
|
||||||
from ansible.plugins.connections import ConnectionBase
|
from ansible.plugins.connections import ConnectionBase
|
||||||
from ansible.plugins import shell_loader
|
from ansible.plugins import shell_loader
|
||||||
from ansible.utils.path import makedirs_safe
|
from ansible.utils.path import makedirs_safe
|
||||||
|
from ansible.utils.unicode import to_bytes
|
||||||
|
|
||||||
|
|
||||||
class Connection(ConnectionBase):
|
class Connection(ConnectionBase):
|
||||||
|
@ -155,7 +156,7 @@ class Connection(ConnectionBase):
|
||||||
def exec_command(self, cmd, tmp_path, executable='/bin/sh', in_data=None):
|
def exec_command(self, cmd, tmp_path, executable='/bin/sh', in_data=None):
|
||||||
super(Connection, self).exec_command(cmd, tmp_path, executable=executable, in_data=in_data)
|
super(Connection, self).exec_command(cmd, tmp_path, executable=executable, in_data=in_data)
|
||||||
|
|
||||||
cmd = cmd.encode('utf-8')
|
cmd = to_bytes(cmd)
|
||||||
cmd_parts = shlex.split(cmd, posix=False)
|
cmd_parts = shlex.split(cmd, posix=False)
|
||||||
if '-EncodedCommand' in cmd_parts:
|
if '-EncodedCommand' in cmd_parts:
|
||||||
encoded_cmd = cmd_parts[cmd_parts.index('-EncodedCommand') + 1]
|
encoded_cmd = cmd_parts[cmd_parts.index('-EncodedCommand') + 1]
|
||||||
|
@ -172,7 +173,9 @@ class Connection(ConnectionBase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
raise AnsibleError("failed to exec cmd %s" % cmd)
|
raise AnsibleError("failed to exec cmd %s" % cmd)
|
||||||
return (result.status_code, '', result.std_out.encode('utf-8'), result.std_err.encode('utf-8'))
|
result.std_out = to_bytes(result.std_out)
|
||||||
|
result.std_err = to_bytes(result.std_err)
|
||||||
|
return (result.status_code, '', result.std_out, result.std_err)
|
||||||
|
|
||||||
def put_file(self, in_path, out_path):
|
def put_file(self, in_path, out_path):
|
||||||
super(Connection, self).put_file(in_path, out_path)
|
super(Connection, self).put_file(in_path, out_path)
|
||||||
|
|
Loading…
Reference in a new issue