Hi,

can you reproduce this issue in the current 2.7.7+dfsg-1? I recently switched
the ansible package from python 2 to 3, and python 3 handles encoding very
differently.

Regards,
Lee

On Tue, 29 Aug 2017 10:19:44 +0100 Klaus Ethgen <kl...@ethgen.de> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA512
> 
> Package: ansible
> Version: 2.3.1.0+dfsg-2
> Severity: important
> 
> I have the following stuff in my ansible tasks:
> {{{yaml
> - - name: Keep all passwd-entries in /etc/password sane
>   replace:
>      dest: /etc/passwd
>      regexp: '^([^:]+):[^:]*:'
>      replace: '\1:x:'
> }}}
> 
> This was working without problems until the update to 2.3. The reason is
> that replace is not encoding agnostic anymore and you have to specify an
> encoding. Unfortunatelly there are two problems with that:
> - - /etc/passwd has different encodings in every line (The gecos field
>   with the name) So there cannot be a encoding specified for the whole
>   file.
> - - Even if I specify the encoding, the playbook is used in old versions
>   too (mainly on stable debian or devuan) and there, an encoding
>   parameter will create an error.
> 
> In the end, utf8 is the worst charset for something that should be
> robust as utf8 has holes and unspeciffied chars in the specifkation.
> 
> This problem currently produce the following failure on all machines
> with unstable (3):
>    TASK [security : Keep all passwd-entries in /etc/password sane] 
> ****************
>    An exception occurred during task execution. To see the full traceback, 
> use -vvv. The error was: UnicodeDecodeError: 'utf8' codec can't decode byte 
> 0xee in position 668: invalid continuation byte
>    fatal: [ikki]: FAILED! => {"changed": false, "failed": true, 
> "module_stderr": "Traceback (most recent call last):\n  File 
> \"/tmp/ansible_jSTtga/ansible_module_replace.py\", line 200, in <module>\n    
> main()\n  File \"/tmp/ansible_jSTtga/ansible_module_replace.py\", line 169, 
> in main\n    contents = to_text(f.read(), errors='surrogate_or_strict')\n  
> File 
> \"/tmp/ansible_jSTtga/ansible_modlib.zip/ansible/module_utils/_text.py\", 
> line 232, in to_text\n  File \"/usr/lib/python2.7/encodings/utf_8.py\", line 
> 16, in decode\n    return codecs.utf_8_decode(input, errors, 
> True)\nUnicodeDecodeError: 'utf8' codec can't decode byte 0xee in position 
> 668: invalid continuation byte\n", "module_stdout": "", "msg": "MODULE 
> FAILURE", "rc": 0}
> 
> The character that breaks stuff is a name of one of my users: Benoït
> which is not that uncommon.
> 
> - -- System Information:
> Debian Release: buster/sid
>   APT prefers unstable
>   APT policy: (500, 'unstable'), (500, 'testing'), (400, 'unstable'), (1, 
> 'experimental')
> Architecture: amd64 (x86_64)
> Foreign Architectures: i386
> 
> Kernel: Linux 4.11.9 (SMP w/8 CPU cores)
> Locale: LANG=de_DE, LC_CTYPE=de_DE (charmap=ISO-8859-1), LANGUAGE=de_DE:en 
> (charmap=ISO-8859-1)
> Shell: /bin/sh linked to /bin/dash
> Init: sysvinit (via /sbin/init)
> 
> Versions of packages ansible depends on:
> ii  python                2.7.13-2
> ii  python-crypto         2.6.1-7+b1
> ii  python-httplib2       0.9.2+dfsg-1
> ii  python-jinja2         2.9.6-1
> ii  python-netaddr        0.7.18-2
> ii  python-paramiko       2.0.0-1
> ii  python-pkg-resources  36.2.7-2
> ii  python-yaml           3.12-1+b1
> 

Reply via email to