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
Fix to output string of items rather than unicode of items. #39864
Conversation
## Fix to output string of items rather than unicode of items. Original output: ok: [172.16.0.2] => (item=[u'httpd', u'perl']) changed: [172.16.0.3] => (item=[u'httpd', u'perl']) New output: ok: [172.16.0.2] => (item=['httpd', 'perl']) changed: [172.16.0.3] => (item=['httpd', 'perl'])
I'm unsure what has failed, but would appreciate some feedback on the code and/or idea of the change. There might be another method that would be more acceptable?. |
The test
The test
|
Removed whitespace and extra #
@@ -227,7 +227,8 @@ def _get_item(self, result): | |||
item = result.get('_ansible_item_label') | |||
else: | |||
item = result.get('item', None) | |||
|
|||
#Fix to output string of items rather than unicode of items. | |||
item = [str(x) for x in item] |
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.
A couple of things:
- you are assuming item is a list, it can be any type
- str() is not a good function across versions of python, that is why we have to_text and to_native
The test
|
CI failure in unit tests: https://app.shippable.com/github/ansible/ansible/runs/64347/3/tests CI failure in integration tests likely due to this warning:
|
SUMMARY
Fix to output string of items rather than unicode of items.
While looking into callback modules and seeing outputs, I came accross this anomoly. Ansible normally outputs in strings, and not unicode, however when using with_items it outputs the list in a unicode format.
After searching, I found that converting the list within the get_items method of initi.py fixed this.
ISSUE TYPE
COMPONENT NAME
initi.py
ANSIBLE VERSION
ADDITIONAL INFORMATION
This effects output to the screen via the callback modules, and should not effect any existing roles or aspects of ansible.
Code to reproduce:
Output changes: