diff --git a/lib/ansible/modules/network/aireos/aireos_command.py b/lib/ansible/modules/network/aireos/aireos_command.py index 2c759c9c8c5..c06f6bf46c9 100644 --- a/lib/ansible/modules/network/aireos/aireos_command.py +++ b/lib/ansible/modules/network/aireos/aireos_command.py @@ -120,12 +120,13 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.network.common.utils import ComplexList from ansible.module_utils.network.common.parsing import Conditional from ansible.module_utils.six import string_types +from ansible.module_utils._text import to_text def to_lines(stdout): for item in stdout: if isinstance(item, string_types): - item = str(item).split('\n') + item = to_text(item, errors='surrogate_then_replace').split('\n') yield item diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py index d5937f3a7e9..a189b8da08d 100644 --- a/lib/ansible/plugins/connection/network_cli.py +++ b/lib/ansible/plugins/connection/network_cli.py @@ -306,7 +306,6 @@ class Connection(NetworkConnectionBase): def __init__(self, play_context, new_stdin, *args, **kwargs): super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs) - self._ssh_shell = None self._matched_prompt = None @@ -582,7 +581,7 @@ class Connection(NetworkConnectionBase): if sendonly: return response = self.receive(command, prompt, answer, newline, prompt_retry_check, check_all) - return to_text(response, errors='surrogate_or_strict') + return to_text(response, errors='surrogate_then_replace') except (socket.timeout, AttributeError): self.queue_message('error', traceback.format_exc()) raise AnsibleConnectionFailure("timeout value %s seconds reached while trying to send command: %s" diff --git a/test/units/modules/network/aireos/test_aireos_command.py b/test/units/modules/network/aireos/test_aireos_command.py index b7fc8f42834..247d66492dc 100644 --- a/test/units/modules/network/aireos/test_aireos_command.py +++ b/test/units/modules/network/aireos/test_aireos_command.py @@ -25,6 +25,7 @@ from units.compat.mock import patch from ansible.modules.network.aireos import aireos_command from units.modules.utils import set_module_args from .aireos_module import TestCiscoWlcModule, load_fixture +from ansible.module_utils import six class TestCiscoWlcCommandModule(TestCiscoWlcModule): @@ -105,3 +106,17 @@ class TestCiscoWlcCommandModule(TestCiscoWlcModule): commands = ['show sysinfo', 'show sysinfo'] set_module_args(dict(commands=commands, wait_for=wait_for, match='all')) self.execute_module(failed=True) + + def test_aireos_command_to_lines_non_ascii(self): + ''' Test data is one variation of the result of a `show run-config commands` + command on Cisco WLC version 8.8.120.0 ''' + test_data = ''' + wlan flexconnect learn-ipaddr 101 enable + `\xc8\x92\xef\xbf\xbdR\x7f`\xc8\x92\xef\xbf\xbdR\x7f` + wlan wgb broadcast-tagging disable 1 + '''.strip() + test_string = six.u(test_data) + test_stdout = [test_string, ] + result = list(aireos_command.to_lines(test_stdout)) + print(result[0]) + self.assertEqual(len(result[0]), 3)