-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
to_nice_yaml
unable to handle unicode characters
#10243
Comments
I was able to reproduce this issue on Fedora 21 with jinja2 2.7.3. Something like this was supposed to have been fixed in a newer version of Jinja2 (pallets/jinja#304). I tried to update jinja2 to version 2.8.dev0 and the issue reported here isn't fixed by that. Adding some debugging code throughout Ansible and Jinja2 modules, I can see the encoding is 'ascii' (ansible/../template.py and jinja2/../template/utils.py, for instance). Workaround seems to edit ansible-playbook and add this to main():
But this seems too drastic. FYI, The 'data' parameter passed to template_from_string() IS unicode. |
Actually, python2 code should never, ever call sys.setdefaultencoding('utf-8'). (I know there's some pieces of code in ansible modules that is doing this and I'm hoping to remove them for v2). I'm trying to get some time to write up a blog post about why that is sometime in the near future. We'll see :-) It looks like the problem is that the to_nice_yaml filter is returning values of type str but jinja2 needs values of type unicode when the value contains non-ascii characters. I'll push a commit in a little bit that should fix this. |
That commit should fix things for you. A few weeks ago I tried to go through the filters and fix ones that could return str values with non-ascii characters but obviously I missed this one. If you run across any other ones that also throw a UnicodeDecode/UnicodeEncodeError feel free to open a bug and ping me on IRC if you think I might have missed it (abadger1999 in #ansible on freenode) Closing This TicketHi! We believe recent commits (likely detailed above) should resolve this question or problem for you. This will also be included in the next major release. If you continue seeing any problems related to this issue, or if you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:
Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular Thank you! |
Thank you for the very quick response, works like a charm! |
Issue Type:
Bug Report
Ansible Version:
1.8.2
Environment:
Ubuntu 14.04
Summary:
If you use
{{ somevar|to_nice_yaml }}
andsomevar
contains unicode characters (such as ä,à), the task fails.Steps To Reproduce:
Expected Results:
"T\\xE9\\xEA\\xE8st"\n
Actual Results:
The text was updated successfully, but these errors were encountered: