* 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
This commit is contained in:
parent
e67459df86
commit
fa2edfa1ef
1 changed files with 5 additions and 3 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue