diff options
author | Matt Clay <matt@mystile.com> | 2019-01-14 13:06:47 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-14 13:06:47 -0800 |
commit | 465df0ef8d27d7fd534f521335db11490ebd43bc (patch) | |
tree | 08dcad3ddd2384fd9ed3f175d18cf0d322024110 /lib | |
parent | 15b1a31aa8c1dc21689bd8030eadbc8c4a53eb04 (diff) | |
download | ansible-465df0ef8d27d7fd534f521335db11490ebd43bc.tar.gz |
Fix encoding issues with file paths. (#50830)
* Fix encoding issues with file paths.
Discovered while testing with ANSIBLE_CONFIG env var set to a path
that contained unicode characters while LC_ALL=C.
* Fix unit tests.
* Fix another path encoding issue.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ansible/config/manager.py | 8 | ||||
-rw-r--r-- | lib/ansible/playbook/__init__.py | 4 | ||||
-rw-r--r-- | lib/ansible/plugins/vars/host_group_vars.py | 4 | ||||
-rw-r--r-- | lib/ansible/vars/manager.py | 4 |
4 files changed, 10 insertions, 10 deletions
diff --git a/lib/ansible/config/manager.py b/lib/ansible/config/manager.py index 603f2fc5d3..f768a27fe9 100644 --- a/lib/ansible/config/manager.py +++ b/lib/ansible/config/manager.py @@ -186,7 +186,7 @@ def find_ini_config_file(warnings=None): path_from_env = os.getenv("ANSIBLE_CONFIG", SENTINEL) if path_from_env is not SENTINEL: path_from_env = unfrackpath(path_from_env, follow=False) - if os.path.isdir(path_from_env): + if os.path.isdir(to_bytes(path_from_env)): path_from_env = os.path.join(path_from_env, "ansible.cfg") potential_paths.append(path_from_env) @@ -214,7 +214,7 @@ def find_ini_config_file(warnings=None): potential_paths.append("/etc/ansible/ansible.cfg") for path in potential_paths: - if os.path.exists(path): + if os.path.exists(to_bytes(path)): break else: path = None @@ -254,7 +254,7 @@ class ConfigManager(object): # consume configuration if self._config_file: - if os.path.exists(self._config_file): + if os.path.exists(to_bytes(self._config_file)): # initialize parser and read config self._parse_config_file() @@ -288,7 +288,7 @@ class ConfigManager(object): if cfile is not None: if ftype == 'ini': self._parsers[cfile] = configparser.ConfigParser() - with open(cfile, 'rb') as f: + with open(to_bytes(cfile), 'rb') as f: try: cfg_text = to_text(f.read(), errors='surrogate_or_strict') except UnicodeError as e: diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 9237478ddf..a72f5fecd1 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -23,7 +23,7 @@ import os from ansible import constants as C from ansible.errors import AnsibleParserError -from ansible.module_utils._text import to_text, to_native +from ansible.module_utils._text import to_bytes, to_text, to_native from ansible.playbook.play import Play from ansible.playbook.playbook_include import PlaybookInclude from ansible.plugins.loader import get_all_plugin_loaders @@ -68,7 +68,7 @@ class Playbook: for name, obj in get_all_plugin_loaders(): if obj.subdir: plugin_path = os.path.join(self._basedir, obj.subdir) - if os.path.isdir(plugin_path): + if os.path.isdir(to_bytes(plugin_path)): obj.add_directory(plugin_path) try: diff --git a/lib/ansible/plugins/vars/host_group_vars.py b/lib/ansible/plugins/vars/host_group_vars.py index fd80a0c304..5a412e215d 100644 --- a/lib/ansible/plugins/vars/host_group_vars.py +++ b/lib/ansible/plugins/vars/host_group_vars.py @@ -77,12 +77,12 @@ class VarsModule(BaseVarsPlugin): try: found_files = [] # load vars - opath = os.path.realpath(os.path.join(self._basedir, subdir)) + b_opath = os.path.realpath(to_bytes(os.path.join(self._basedir, subdir))) + opath = to_text(b_opath) key = '%s.%s' % (entity.name, opath) if cache and key in FOUND: found_files = FOUND[key] else: - b_opath = to_bytes(opath) # no need to do much if path does not exist for basedir if os.path.exists(b_opath): if os.path.isdir(b_opath): diff --git a/lib/ansible/vars/manager.py b/lib/ansible/vars/manager.py index 83a61d5e31..290d72b2d4 100644 --- a/lib/ansible/vars/manager.py +++ b/lib/ansible/vars/manager.py @@ -35,7 +35,7 @@ from ansible import constants as C from ansible.errors import AnsibleError, AnsibleParserError, AnsibleUndefinedVariable, AnsibleFileNotFound, AnsibleAssertionError, AnsibleTemplateError from ansible.inventory.host import Host from ansible.inventory.helpers import sort_groups, get_group_vars -from ansible.module_utils._text import to_native +from ansible.module_utils._text import to_bytes, to_native from ansible.module_utils.common._collections_compat import Mapping, MutableMapping, Sequence from ansible.module_utils.six import iteritems, text_type, string_types from ansible.plugins.loader import lookup_loader, vars_loader @@ -240,7 +240,7 @@ class VariableManager: for inventory_dir in self._inventory._sources: if ',' in inventory_dir and not os.path.exists(inventory_dir): # skip host lists continue - elif not os.path.isdir(inventory_dir): # always pass 'inventory directory' + elif not os.path.isdir(to_bytes(inventory_dir)): # always pass 'inventory directory' inventory_dir = os.path.dirname(inventory_dir) for plugin in vars_loader.all(): |