Commit ee831e10 by Toshio Kuratomi

Fix v2 for #10426

Note: In v1 we fix this by transforming into unicode just before we use
it (when we send it to jinja2) because jinja2 cannot handle non-ascii
characters in str.

In v2 our model is that all text values need to be stored as unicode
type internally.  So we transform this to unicode when we read it from
the inventory file and save it into the internal dict instead.
parent 4710a07f
...@@ -27,6 +27,7 @@ from ansible.inventory.host import Host ...@@ -27,6 +27,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
class InventoryParser(object): class InventoryParser(object):
""" """
...@@ -53,7 +54,7 @@ class InventoryParser(object): ...@@ -53,7 +54,7 @@ class InventoryParser(object):
def _parse_value(v): def _parse_value(v):
if "#" not in v: if "#" not in v:
try: try:
return ast.literal_eval(v) v = ast.literal_eval(v)
# Using explicit exceptions. # Using explicit exceptions.
# Likely a string that literal_eval does not like. We wil then just set it. # Likely a string that literal_eval does not like. We wil then just set it.
except ValueError: except ValueError:
...@@ -62,7 +63,7 @@ class InventoryParser(object): ...@@ -62,7 +63,7 @@ class InventoryParser(object):
except SyntaxError: except SyntaxError:
# Is this a hash with an equals at the end? # Is this a hash with an equals at the end?
pass pass
return v return to_unicode(v, nonstring='passthru', errors='strict')
# [webservers] # [webservers]
# alpha # alpha
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment