UnicodeDecodeError with Ansible 1.9.4 and German Letter

117 views
Skip to first unread message

Thoralf Liersch

unread,
Oct 15, 2015, 8:56:27 AM10/15/15
to Ansible Project
Hi,

i have a problem to provisioning a windows client.
The Windows Client is a Windows 10 Prof, the management machine is a mac osx or a ubuntu. I have both the same problem.

the command: ansible berater -m raw -a "ipconfig" -i hosts -vvvvv
works fine and gives me the output what i want
the output:
ansible berater -m raw -a "ipconfig" -i hosts -vvvvv
<10.8.32.91> ESTABLISH WINRM CONNECTION FOR USER: Admin on PORT 5986 TO 10.8.32.91
<10.8.32.91> WINRM CONNECT: transport=plaintext endpoint=https://10.8.32.91:5986/wsman
<10.8.32.91> EXEC ipconfig
<10.8.32.91> WINRM EXEC 'ipconfig' []
<10.8.32.91> WINRM RESULT <Response code 0, out " Windows-IP-Konfigu", err "">
<10.8.32.91> WINRM STDOUT Windows-IP-Konfiguration Drahtlos-LAN-Adapter Drahtlosnetzwerkverbindung: Medienstatus. . . . . . . . . . . : Medium getrennt Verbindungsspezifisches DNS-Suffix: Drahtlos-LAN-Adapter LAN-Verbindung* 2: Medienstatus. . . . . . . . . . . : Medium getrennt Verbindungsspezifisches DNS-Suffix: Drahtlos-LAN-Adapter LAN-Verbindung* 4: Medienstatus. . . . . . . . . . . : Medium getrennt Verbindungsspezifisches DNS-Suffix: Ethernet-Adapter LAN-Verbindung: Verbindungsspezifisches DNS-Suffix: fc.local Verbindungslokale IPv6-Adresse . : fe80::c566:aab4:dee0:1829%9 IPv4-Adresse . . . . . . . . . . : 10.8.32.91 Subnetzmaske . . . . . . . . . . : 255.255.255.0 Standardgateway . . . . . . . . . : 10.8.32.1 Ethernet-Adapter Bluetooth-Netzwerkverbindung 2: Medienstatus. . . . . . . . . . . : Medium getrennt Verbindungsspezifisches DNS-Suffix: Tunneladapter isatap.fc.local: Medienstatus. . . . . . . . . . . : Medium getrennt Verbindungsspezifisches DNS-Suffix: fc.local Tunneladapter Teredo Tunneling Pseudo-Interface: Verbindungsspezifisches DNS-Suffix: IPv6-Adresse. . . . . . . . . . . : 2001:0:9d38:6abd:cdc:e5:abd1:a435 Verbindungslokale IPv6-Adresse . : fe80::cdc:e5:abd1:a435%6 Standardgateway . . . . . . . . . : ::
<10.8.32.91> WINRM STDERR
10.8.32.91 | success | rc=0 >>

Windows-IP-Konfiguration


Drahtlos-LAN-Adapter Drahtlosnetzwerkverbindung:

   Medienstatus. . . . . . . . . . . : Medium getrennt
   Verbindungsspezifisches DNS-Suffix:

Drahtlos-LAN-Adapter LAN-Verbindung* 2:

   Medienstatus. . . . . . . . . . . : Medium getrennt
   Verbindungsspezifisches DNS-Suffix:

Drahtlos-LAN-Adapter LAN-Verbindung* 4:

   Medienstatus. . . . . . . . . . . : Medium getrennt
   Verbindungsspezifisches DNS-Suffix:

Ethernet-Adapter LAN-Verbindung:

   Verbindungsspezifisches DNS-Suffix: fc.local
   Verbindungslokale IPv6-Adresse  . : fe80::c566:aab4:dee0:1829%9
   IPv4-Adresse  . . . . . . . . . . : 10.8.32.91
   Subnetzmaske  . . . . . . . . . . : 255.255.255.0
   Standardgateway . . . . . . . . . : 10.8.32.1

Ethernet-Adapter Bluetooth-Netzwerkverbindung 2:

   Medienstatus. . . . . . . . . . . : Medium getrennt
   Verbindungsspezifisches DNS-Suffix:

Tunneladapter isatap.fc.local:

   Medienstatus. . . . . . . . . . . : Medium getrennt
   Verbindungsspezifisches DNS-Suffix: fc.local

Tunneladapter Teredo Tunneling Pseudo-Interface:

   Verbindungsspezifisches DNS-Suffix:
   IPv6-Adresse. . . . . . . . . . . : 2001:0:9d38:6abd:cdc:e5:abd1:a435
   Verbindungslokale IPv6-Adresse  . : fe80::cdc:e5:abd1:a435%6
   Standardgateway . . . . . . . . . : ::



the command: ansible berater -m raw -a "ipconfig /all" -i hosts -vvvvv
works not. the output included german letters and produce the error: UnicodeDecodeError: 'ascii' codec can't decode byte 0x84 in position 90: ordinal not in range(128)
the output:
ansible berater -m raw -a "ipconfig /all" -i hosts -vvvvv
<10.8.32.91> ESTABLISH WINRM CONNECTION FOR USER: Admin on PORT 5986 TO 10.8.32.91
<10.8.32.91> WINRM CONNECT: transport=plaintext endpoint=https://10.8.32.91:5986/wsman
<10.8.32.91> EXEC ipconfig /all
<10.8.32.91> WINRM EXEC 'ipconfig' ['/all']
<10.8.32.91> WINRM RESULT <Response code 0, out " Windows-IP-Konfigu", err "">
<10.8.32.91> WINRM STDOUT Windows-IP-Konfiguration Hostname . . . . . . . . . . . . : FFG-TCTA-031 Prim�res DNS-Suffix . . . . . . . : Knotentyp . . . . . . . . . . . . : Hybrid IP-Routing aktiviert . . . . . . : Nein WINS-Proxy aktiviert . . . . . . : Nein DNS-Suffixsuchliste . . . . . . . : fc.local Drahtlos-LAN-Adapter Drahtlosnetzwerkverbindung: Medienstatus. . . . . . . . . . . : Medium getrennt Verbindungsspezifisches DNS-Suffix: Beschreibung. . . . . . . . . . . : Intel(R) Wireless-N 7260 Physische Adresse . . . . . . . . : 7C-5C-F8-19-B4-CD DHCP aktiviert. . . . . . . . . . : Ja Autokonfiguration aktiviert . . . : Ja Drahtlos-LAN-Adapter LAN-Verbindung* 2: Medienstatus. . . . . . . . . . . : Medium getrennt Verbindungsspezifisches DNS-Suffix: Beschreibung. . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter Physische Adresse . . . . . . . . : 7C-5C-F8-19-B4-CE DHCP aktiviert. . . . . . . . . . : Ja Autokonfiguration aktiviert . . . : Ja Drahtlos-LAN-Adapter LAN-Verbindung* 4: Medienstatus. . . . . . . . . . . : Medium getrennt Verbindungsspezifisches DNS-Suffix: Beschreibung. . . . . . . . . . . : Microsoft Hosted Network Virtual Adapter Physische Adresse . . . . . . . . : 7E-5C-F8-19-B4-CD DHCP aktiviert. . . . . . . . . . : Ja Autokonfiguration aktiviert . . . : Ja Ethernet-Adapter LAN-Verbindung: Verbindungsspezifisches DNS-Suffix: fc.local Beschreibung. . . . . . . . . . . : Intel(R) Ethernet Connection I218-V Physische Adresse . . . . . . . . : B8-AE-ED-72-80-22 DHCP aktiviert. . . . . . . . . . : Ja Autokonfiguration aktiviert . . . : Ja Verbindungslokale IPv6-Adresse . : fe80::c566:aab4:dee0:1829%9(Bevorzugt) IPv4-Adresse . . . . . . . . . . : 10.8.32.91(Bevorzugt) Subnetzmaske . . . . . . . . . . : 255.255.255.0 Lease erhalten. . . . . . . . . . : Donnerstag, 15. Oktober 2015 11:05:54 Lease l�uft ab. . . . . . . . . . : Donnerstag, 22. Oktober 2015 11:05:51 Standardgateway . . . . . . . . . : 10.8.32.1 DHCP-Server . . . . . . . . . . . : 10.8.32.1 DHCPv6-IAID . . . . . . . . . . . : 247480277 DHCPv6-Client-DUID. . . . . . . . : 00-01-00-01-1D-94-13-C5-B8-AE-ED-72-80-22 DNS-Server . . . . . . . . . . . : 10.8.32.1 NetBIOS �ber TCP/IP . . . . . . . : Aktiviert Ethernet-Adapter Bluetooth-Netzwerkverbindung 2: Medienstatus. . . . . . . . . . . : Medium getrennt Verbindungsspezifisches DNS-Suffix: Beschreibung. . . . . . . . . . . : Bluetooth Device (Personal Area Network) Physische Adresse . . . . . . . . : 7C-5C-F8-19-B4-D1 DHCP aktiviert. . . . . . . . . . : Ja Autokonfiguration aktiviert . . . : Ja Tunneladapter isatap.fc.local: Medienstatus. . . . . . . . . . . : Medium getrennt Verbindungsspezifisches DNS-Suffix: fc.local Beschreibung. . . . . . . . . . . : Microsoft ISATAP Adapter Physische Adresse . . . . . . . . : 00-00-00-00-00-00-00-E0 DHCP aktiviert. . . . . . . . . . : Nein Autokonfiguration aktiviert . . . : Ja Tunneladapter Teredo Tunneling Pseudo-Interface: Verbindungsspezifisches DNS-Suffix: Beschreibung. . . . . . . . . . . : Teredo Tunneling Pseudo-Interface Physische Adresse . . . . . . . . : 00-00-00-00-00-00-00-E0 DHCP aktiviert. . . . . . . . . . : Nein Autokonfiguration aktiviert . . . : Ja IPv6-Adresse. . . . . . . . . . . : 2001:0:9d38:6abd:cdc:e5:abd1:a435(Bevorzugt) Verbindungslokale IPv6-Adresse . : fe80::cdc:e5:abd1:a435%6(Bevorzugt) Standardgateway . . . . . . . . . : :: DHCPv6-IAID . . . . . . . . . . . : 486539264 DHCPv6-Client-DUID. . . . . . . . : 00-01-00-01-1D-94-13-C5-B8-AE-ED-72-80-22 NetBIOS �ber TCP/IP . . . . . . . : Deaktiviert
<10.8.32.91> WINRM STDERR
10.8.32.91 | FAILED => Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/ansible/runner/__init__.py", line 586, in _executor
    exec_rc = self._executor_internal(host, new_stdin)
  File "/Library/Python/2.7/site-packages/ansible/runner/__init__.py", line 789, in _executor_internal
    return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
  File "/Library/Python/2.7/site-packages/ansible/runner/__init__.py", line 1036, in _executor_internal_inner
    result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
  File "/Library/Python/2.7/site-packages/ansible/runner/action_plugins/raw.py", line 47, in run
    become=self.runner.become)
  File "/Library/Python/2.7/site-packages/ansible/runner/__init__.py", line 1174, in _low_level_exec_command
    in_data=in_data)
  File "/Library/Python/2.7/site-packages/ansible/runner/connection_plugins/winrm.py", line 165, in exec_command
    return (result.status_code, '', result.std_out.encode('utf-8'), result.std_err.encode('utf-8'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0x84 in position 90: ordinal not in range(128)


can anyone help?
thanks thoralf

Toshio Kuratomi

unread,
Oct 15, 2015, 5:09:02 PM10/15/15
to ansible...@googlegroups.com
I don't do anything with Windows unfortunately, but that error
probably means that either result.std_out or result.std_err are
already encoded to bytes. You could see if doing this fixes the
issue:


from ansible.utils.unicode import to_bytes
return (result.status_code, '', to_bytes(result.std_out),
to_bytes(result.std_err))


If it does be sure to let us know so that we can apply it to the upstream code.

-Toshio
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/11343a69-ea58-4c66-90f7-cd305a97c161%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Thoralf Liersch

unread,
Oct 21, 2015, 4:52:27 AM10/21/15
to Ansible Project
where do I install or run this code because

Thoralf Liersch

unread,
Oct 21, 2015, 6:13:15 AM10/21/15
to Ansible Project
ok i have changed in ansible/runner/connection_plugins/winrm.py 

# added new line 30
from ansible.utils.unicode import to_bytes

# deaktivate line 166
# added new line 167
return (result.status_code, '', to_bytes(result.std_out), to_bytes(result.std_err))

this works a bit better. the german letters are not displayed.

Am Donnerstag, 15. Oktober 2015 14:56:27 UTC+2 schrieb Thoralf Liersch:

Toshio Kuratomi

unread,
Oct 21, 2015, 10:47:47 AM10/21/15
to ansible...@googlegroups.com


On Oct 21, 2015 3:13 AM, "Thoralf Liersch" <thoralf...@gmail.com> wrote:
>
> ok i have changed in ansible/runner/connection_plugins/winrm.py 
>
> # added new line 30
> from ansible.utils.unicode import to_bytes
>
> # deaktivate line 166
> # added new line 167
> return (result.status_code, '', to_bytes(result.std_out), to_bytes(result.std_err))
>
> this works a bit better. the german letters are not displayed.
>

Okay, I'll apply this for now then so it's possible for people to continue on.

If someone wants to try getting all characters to properly display they'll need to know what character encoding Windows uses here and in what circumstances the encoding can be different.

-Toshio

> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.

> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/de90c65e-b9c5-4f18-9fa2-2d910251a90a%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages