mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-03 23:20:19 -07:00
Since Connection.execute_command() returns bytes, deal with the repurcussions here.
This commit is contained in:
parent
e2ae3215f6
commit
10750214ea
1 changed files with 16 additions and 6 deletions
|
@ -28,14 +28,14 @@ import stat
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from six import string_types, iteritems
|
from six import binary_type, text_type, iteritems
|
||||||
from six.moves import StringIO
|
from six.moves import StringIO
|
||||||
|
|
||||||
from ansible import constants as C
|
from ansible import constants as C
|
||||||
from ansible.errors import AnsibleError, AnsibleConnectionFailure
|
from ansible.errors import AnsibleError, AnsibleConnectionFailure
|
||||||
from ansible.executor.module_common import modify_module
|
from ansible.executor.module_common import modify_module
|
||||||
from ansible.parsing.utils.jsonify import jsonify
|
from ansible.parsing.utils.jsonify import jsonify
|
||||||
from ansible.utils.unicode import to_bytes
|
from ansible.utils.unicode import to_bytes, to_unicode
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from __main__ import display
|
from __main__ import display
|
||||||
|
@ -479,13 +479,23 @@ class ActionBase:
|
||||||
rc, stdout, stderr = self._connection.exec_command(cmd, in_data=in_data, sudoable=sudoable)
|
rc, stdout, stderr = self._connection.exec_command(cmd, in_data=in_data, sudoable=sudoable)
|
||||||
self._display.debug("command execution done")
|
self._display.debug("command execution done")
|
||||||
|
|
||||||
if not isinstance(stdout, string_types):
|
# stdout and stderr may be either a file-like or a bytes object.
|
||||||
out = ''.join(stdout.readlines())
|
# Convert either one to a text type
|
||||||
|
# Note: when we address non-utf-8 data we'll have to figure out
|
||||||
|
# a better strategy than errors='strict'. Perhaps pass the
|
||||||
|
# errors argument into this method so that the caller can decide or
|
||||||
|
# even make the caller convert to text type so they can choose.
|
||||||
|
if isinstance(stdout, binary_type):
|
||||||
|
out = to_unicode(stdout, errors='strict')
|
||||||
|
elif not isinstance(stdout, text_type):
|
||||||
|
out = to_unicode(b''.join(stdout.readlines()), errors='strict')
|
||||||
else:
|
else:
|
||||||
out = stdout
|
out = stdout
|
||||||
|
|
||||||
if not isinstance(stderr, string_types):
|
if isinstance(stderr, binary_type):
|
||||||
err = ''.join(stderr.readlines())
|
err = to_unicode(stderr, errors='strict')
|
||||||
|
elif not isinstance(stderr, text_type):
|
||||||
|
err = to_unicode(b''.join(stderr.readlines()), errors='strict')
|
||||||
else:
|
else:
|
||||||
err = stderr
|
err = stderr
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue