From fa2edfa1ef503f25f4d68592c00854d950286f5b Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 9 Sep 2015 01:22:53 -0700 Subject: [PATCH] * Make sure we don't sometimes get byte strings instead of unicode strings * Turn strings into byte strings before passing to shlex and turn them back into unicode strings after they are retyurned from there Fixes #12257 --- lib/ansible/inventory/ini.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ansible/inventory/ini.py b/lib/ansible/inventory/ini.py index 8c6038d40a6..36115c57975 100644 --- a/lib/ansible/inventory/ini.py +++ b/lib/ansible/inventory/ini.py @@ -29,7 +29,7 @@ from ansible.inventory.host import Host from ansible.inventory.group import Group from ansible.inventory.expand_hosts import detect_range from ansible.inventory.expand_hosts import expand_hostname_range -from ansible.utils.unicode import to_unicode +from ansible.utils.unicode import to_unicode, to_bytes class InventoryParser(object): """ @@ -56,10 +56,10 @@ class InventoryParser(object): if loader: (data, private) = loader._get_file_contents(filename) - data = data.split('\n') else: with open(filename) as fh: - data = fh.readlines() + data = to_unicode(fh.read()) + data = data.split('\n') self._parse(data) @@ -230,11 +230,13 @@ class InventoryParser(object): # beta:2345 user=admin # we'll tell shlex # gamma sudo=True user=root # to ignore comments + line = to_bytes(line) try: tokens = shlex.split(line, comments=True) except ValueError as e: self._raise_error("Error parsing host definition '%s': %s" % (varstring, e)) + tokens = [ to_unicode(t) for t in tokens] (hostnames, port) = self._expand_hostpattern(tokens[0]) hosts = self._Hosts(hostnames, port)