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

Ansible throws an exception if inventory file path contains non-ascii characters #17932

Closed
dmromanov opened this issue Oct 7, 2016 · 5 comments · Fixed by #17961
Closed

Ansible throws an exception if inventory file path contains non-ascii characters #17932

dmromanov opened this issue Oct 7, 2016 · 5 comments · Fixed by #17961
Labels
affects_2.1 This issue/PR affects Ansible v2.1 bug This issue/PR relates to a bug.

Comments

@dmromanov
Copy link

ISSUE TYPE
  • Bug Report
COMPONENT NAME

core

ANSIBLE VERSION

ansible 2.1.2.0

CONFIGURATION

default

OS / ENVIRONMENT

Ubuntu 16.04
Python 2.7.12

SUMMARY

Ansible fails to load inventory file if path contains non-ascii characters and throws an exception.
Affects ansible and ansible-playbook commands.

STEPS TO REPRODUCE

Create an ansible project and put in a folder containing non-unicode characters (e.g. cyrillic).
Run ansible.

ansible -i test -m setup all -vvvv
EXPECTED RESULTS

Command runs without an error.

ACTUAL RESULTS
$ ansible -i test -m setup all -vvvv
Using /home/dromanov/Документы/ansible/ansible.cfg as config file
ERROR! Unexpected Exception: 'ascii' codec can't decode byte 0xd0 in position 15: ordinal not in range(128)
the full traceback was:

Traceback (most recent call last):
  File "/usr/bin/ansible", line 92, in <module>
    exit_code = cli.run()
  File "/usr/lib/python2.7/dist-packages/ansible/cli/adhoc.py", line 129, in run
    inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=self.options.inventory)
  File "/usr/lib/python2.7/dist-packages/ansible/inventory/__init__.py", line 75, in __init__
    self._group_vars_files = self._find_group_vars_files(self._basedir)
  File "/usr/lib/python2.7/dist-packages/ansible/inventory/__init__.py", line 764, in _find_group_vars_files
    found_vars = set(os.listdir(unicode(path)))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 15: ordinal not in range(128)

@ansibot ansibot added bug_report affects_2.1 This issue/PR affects Ansible v2.1 labels Oct 7, 2016
@robinro
Copy link
Contributor

robinro commented Oct 10, 2016

@dmromanov Please try ansible 2.2 rc1 or the devel version and report back whether those still show the issue. There were recent fixes regarding unicode handling and especially the line that produced your issue.

@dmromanov
Copy link
Author

dmromanov commented Oct 10, 2016

@robinro
It did not work.

$ ansible --version
ansible 2.3.0 (devel 03765ba65e) last updated 2016/10/10 12:43:11 (GMT +300)
  lib/ansible/modules/core: (detached HEAD b4f6a25195) last updated 2016/10/10 12:43:24 (GMT +300)
  lib/ansible/modules/extras: (detached HEAD 734aa8f8e9) last updated 2016/10/10 12:43:24 (GMT +300)
  config file = /home/dromanov/Документы/ansible/ansible.cfg
  configured module search path = Default w/o overrides
$ ansible -i test -m setup all -vvvv
Using /home/dromanov/Документы/ansible/ansible.cfg as config file
ERROR! Unexpected Exception: 'ascii' codec can't decode byte 0xd0 in position 85: ordinal not in range(128)
the full traceback was:

Traceback (most recent call last):
  File "/opt/ansible/bin/ansible", line 103, in <module>
    exit_code = cli.run()
  File "/opt/ansible/lib/ansible/cli/adhoc.py", line 129, in run
    inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=self.options.inventory)
  File "/opt/ansible/lib/ansible/inventory/__init__.py", line 97, in __init__
    self.parse_inventory(host_list)
  File "/opt/ansible/lib/ansible/inventory/__init__.py", line 150, in parse_inventory
    self.parser = get_file_parser(host_list, self.groups, self._loader)
  File "/opt/ansible/lib/ansible/inventory/dir.py", line 73, in get_file_parser
    myerr.append('Attempted to read "%s" as YAML: %s' % (hostsfile, to_native(e)))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 85: ordinal not in range(128)

robinro pushed a commit to robinro/ansible that referenced this issue Oct 10, 2016
@robinro
Copy link
Contributor

robinro commented Oct 10, 2016

I was able to reproduce the issue and now pushed a fix as #17961
With that fix I'm able to load a ini based inventory file with a non-ascii character in the filename

Please have a look and let me know whether this fixes your issue.

@dmromanov
Copy link
Author

@robinro Thank you! Your patch fixed the issue!

abadger pushed a commit that referenced this issue Oct 15, 2016
Fixes #17932

(cherry picked from commit 3922328)
abadger pushed a commit that referenced this issue Oct 15, 2016
sereinity pushed a commit to sereinity-forks/ansible that referenced this issue Jan 25, 2017
Fixes ansible#17932

(cherry picked from commit 3922328)
@Chugajstyr
Copy link

Chugajstyr commented Apr 20, 2017

Still not fixed.

OS - Linux Mint 18.1 "Serena" (Ubuntu 16.04 based)
python version = 2.7.12
ansible 2.3.0.0.

~/Документи/1 $ ansible -i test -m setup all -vvvv Traceback (most recent call last): File "/usr/bin/ansible", line 43, in <module> import ansible.constants as C File "/usr/lib/python2.7/dist-packages/ansible/constants.py", line 200, in <module> DEFAULT_ROLES_PATH = get_config(p, DEFAULTS, 'roles_path', 'ANSIBLE_ROLES_PATH', '/etc/ansible/roles', value_type='pathlist', expand_relative_paths=True) File "/usr/lib/python2.7/dist-packages/ansible/constants.py", line 116, in get_config for x in value.split(os.pathsep)] File "/usr/lib/python2.7/dist-packages/ansible/constants.py", line 54, in shell_expand path = os.path.join(CFGDIR, path) File "/usr/lib/python2.7/posixpath.py", line 73, in join path += '/' + b UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 10: ordinal not in range(128)

@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 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.1 This issue/PR affects Ansible v2.1 bug This issue/PR relates to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants