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
Add support for unicode in ansible-inventory CLI #74912
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code LGTM, would be nice to have test to avoid regressions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh. I've looked at this file wholistically and it's unicode handling looks like it is very, very wrong. I think that it needs a lot of changes to work right. ping me on irc and I can walk through it with you.
So as a summary of what this PR does:
As per above, this PR is an improvement to the unicode support in Certainly there is more to improve but I don't think we should hold off on merging this (unless someone thinks the PR as is is incorrect of course). We can follow up in another PR. We can also leave #57378 open. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I discussed this with mkrizek on IRC and he fixed the major problem that I saw (writing the file as text which can traceback and could write the file in non-utf8 which ansible will not read correctly) and we also agreed on the other things that should be fixed in a followup(s) (fix use of to_native when calling display.*(), moving the toml routines to a [possibly private] utility file, moving the transformation of yaml output from bytes to text into AnsibleDumper).
We also discussed the toml output a bit. On Python2, the toml library both removes and adds backslashes that it shouldn't, which badly mangles the escaped strings. it would be possible to fix the problem in our toml_dumps function https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/inventory/toml.py#L118 by overriding the str, unicode (and AnsibleUnicode, AnsibleUnsafeBytes, and AnsibleUnsafeText) handlers in dump_funcs
. We could also deprecate use of the toml library and promote use of tomlkit because tomlkit does the right thing here. However, the problem only occurs on Python2. The python3 repr functionality which the toml library relies on handles output of non-ascii characters in a non-supportive locale in a different way such that the toml library does not mangle those.
(cherry picked from commit 5ac1b04)
SUMMARY
Fixes #57378
ISSUE TYPE
COMPONENT NAME
lib/ansible/cli/inventory.py