Fix python3 and nonascii handling in inventory plugins

Fixes #30663
This commit is contained in:
Toshio Kuratomi 2017-09-20 17:01:07 -07:00
commit 72bdf7aa7e
6 changed files with 41 additions and 41 deletions

View file

@ -27,8 +27,7 @@ EXAMPLES = r'''
import os
from ansible.errors import AnsibleError, AnsibleParserError
from ansible.module_utils.six import string_types
from ansible.module_utils._text import to_bytes, to_text, to_native
from ansible.module_utils._text import to_bytes, to_native
from ansible.parsing.utils.addresses import parse_address
from ansible.plugins.inventory import BaseInventoryPlugin
@ -40,9 +39,9 @@ class InventoryModule(BaseInventoryPlugin):
def verify_file(self, host_list):
valid = False
b_path = to_bytes(host_list)
b_path = to_bytes(host_list, errors='surrogate_or_strict')
if not os.path.exists(b_path) and ',' in host_list:
valid = True
valid = True
return valid
def parse(self, inventory, loader, host_list, cache=True):
@ -64,4 +63,4 @@ class InventoryModule(BaseInventoryPlugin):
if host not in self.inventory.hosts:
self.inventory.add_host(host, group='ungrouped', port=port)
except Exception as e:
raise AnsibleParserError("Invalid data from string, could not parse: %s" % str(e))
raise AnsibleParserError("Invalid data from string, could not parse: %s" % to_native(e))