Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash with file module when directories have non utf-8 files #23861

Closed
Yannig opened this issue Apr 21, 2017 · 1 comment · Fixed by #27169 or #27259
Closed

Crash with file module when directories have non utf-8 files #23861

Yannig opened this issue Apr 21, 2017 · 1 comment · Fixed by #27169 or #27259
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. c:module_utils/basic c:module_utils/ module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@Yannig
Copy link
Contributor

Yannig commented Apr 21, 2017

Bug Report
COMPONENT NAME

file

ANSIBLE VERSION
ansible 2.4.0 (recursive-crash-non-utf8 78836ec0b9) last updated 2017/04/21 15:31:54 (GMT +200)
  config file = /etc/ansible/ansible.cfg
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
CONFIGURATION

Nothing special

OS / ENVIRONMENT

Nothing special

SUMMARY

When launching file module with recurse = yes on directories with non utf-8 files, Ansible crash with the following message:

LookupError: unknown error handler name 'surrogate_then_strict'
STEPS TO REPRODUCE

You can retrieve an example at the following location: https://github.com/Yannig/yannig-ansible-playbooks/tree/master/file-encoding

- name: "Recursive change with non utf-8 filename"
  hosts: localhost
  gather_facts: no
  tasks:
    - name: "Recursive change (crash)"
      file: path=dir mode=0755 recurse=yes
EXPECTED RESULTS

Playbook apply change without crash

ACTUAL RESULTS
exception:
Traceback (most recent call last):
  File "/tmp/ansible_atAUEE/ansible_module_file.py", line 480, in <module>
    main()
  File "/tmp/ansible_atAUEE/ansible_module_file.py", line 362, in main
    changed |= recursive_set_attributes(module, to_bytes(file_args['path'], errors='surrogate_or_strict'), follow, file_args)
  File "/tmp/ansible_atAUEE/ansible_module_file.py", line 171, in recursive_set_attributes
    changed |= module.set_fs_attributes_if_different(tmp_file_args, changed)
  File "/tmp/ansible_atAUEE/ansible_modlib.zip/ansible/module_utils/basic.py", line 1292, in set_fs_attributes_if_different
  File "/tmp/ansible_atAUEE/ansible_modlib.zip/ansible/module_utils/basic.py", line 995, in set_owner_if_different
  File "/tmp/ansible_atAUEE/ansible_modlib.zip/ansible/module_utils/_text.py", line 232, in to_text
  File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
LookupError: unknown error handler name 'surrogate_then_strict'
@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug_report module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. labels Apr 21, 2017
Yannig pushed a commit to Yannig/ansible that referenced this issue Apr 21, 2017
Do not convert path in set_*_if_different.
@s-hertel s-hertel added c:module_utils/ c:module_utils/basic and removed needs_triage Needs a first human triage before being processed. labels Apr 21, 2017
@ansibot ansibot added the support:core This issue/PR relates to code supported by the Ansible Engineering Team. label Jun 29, 2017
@Yannig
Copy link
Contributor Author

Yannig commented Jul 11, 2017

This issue affect also Ansible 2.3.1.
Is there any way to have a feedback on this issue?

abadger added a commit to abadger/ansible that referenced this issue Jul 21, 2017
* surrogate_then_strict doesn't exist.  Switch to surrogate_or_strict
  instead.
* Found some bugs in the _text.py implementation
  * The composed error handlers (error handlers which are made up of two
    or more python encoding error handlers) had a wrong string in it,
    'surrogate_or_escape' doesn't exist.  Replaced that with
    'surrogate_or_replace' which is the correct handler name.
  * Left comment about the implicit conditions that are part of the
    surrogate_then_replace code path

Fixes ansible#23865
Fixes ansible#23861
abadger added a commit that referenced this issue Jul 24, 2017
* surrogate_then_strict doesn't exist.  Switch to surrogate_or_strict
  instead.
* Found some bugs in the _text.py implementation
  * The composed error handlers (error handlers which are made up of two
    or more python encoding error handlers) had a wrong string in it,
    'surrogate_or_escape' doesn't exist.  Replaced that with
    'surrogate_or_replace' which is the correct handler name.
  * Left comment about the implicit conditions that are part of the
    surrogate_then_replace code path

Fixes #23865
Fixes #23861

(cherry picked from commit fc5d71d)
thnee pushed a commit to thnee/ansible that referenced this issue Jul 24, 2017
* surrogate_then_strict doesn't exist.  Switch to surrogate_or_strict
  instead.
* Found some bugs in the _text.py implementation
  * The composed error handlers (error handlers which are made up of two
    or more python encoding error handlers) had a wrong string in it,
    'surrogate_or_escape' doesn't exist.  Replaced that with
    'surrogate_or_replace' which is the correct handler name.
  * Left comment about the implicit conditions that are part of the
    surrogate_then_replace code path

Fixes ansible#23865
Fixes ansible#23861
abadger added a commit to abadger/ansible that referenced this issue Jul 25, 2017
abadger added a commit that referenced this issue Jul 25, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. c:module_utils/basic c:module_utils/ module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
3 participants