* 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 #12257pull/4420/head
parent
e67459df86
commit
fa2edfa1ef
|
@ -29,7 +29,7 @@ from ansible.inventory.host import Host
|
||||||
from ansible.inventory.group import Group
|
from ansible.inventory.group import Group
|
||||||
from ansible.inventory.expand_hosts import detect_range
|
from ansible.inventory.expand_hosts import detect_range
|
||||||
from ansible.inventory.expand_hosts import expand_hostname_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):
|
class InventoryParser(object):
|
||||||
"""
|
"""
|
||||||
|
@ -56,10 +56,10 @@ class InventoryParser(object):
|
||||||
|
|
||||||
if loader:
|
if loader:
|
||||||
(data, private) = loader._get_file_contents(filename)
|
(data, private) = loader._get_file_contents(filename)
|
||||||
data = data.split('\n')
|
|
||||||
else:
|
else:
|
||||||
with open(filename) as fh:
|
with open(filename) as fh:
|
||||||
data = fh.readlines()
|
data = to_unicode(fh.read())
|
||||||
|
data = data.split('\n')
|
||||||
|
|
||||||
self._parse(data)
|
self._parse(data)
|
||||||
|
|
||||||
|
@ -230,11 +230,13 @@ class InventoryParser(object):
|
||||||
# beta:2345 user=admin # we'll tell shlex
|
# beta:2345 user=admin # we'll tell shlex
|
||||||
# gamma sudo=True user=root # to ignore comments
|
# gamma sudo=True user=root # to ignore comments
|
||||||
|
|
||||||
|
line = to_bytes(line)
|
||||||
try:
|
try:
|
||||||
tokens = shlex.split(line, comments=True)
|
tokens = shlex.split(line, comments=True)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
self._raise_error("Error parsing host definition '%s': %s" % (varstring, 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])
|
(hostnames, port) = self._expand_hostpattern(tokens[0])
|
||||||
hosts = self._Hosts(hostnames, port)
|
hosts = self._Hosts(hostnames, port)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue