mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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.
This commit is contained in:
parent
4710a07fb0
commit
ee831e1071
1 changed files with 3 additions and 2 deletions
|
@ -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):
|
||||||
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):
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue