Navigation Menu

Skip to content
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

Closed
wants to merge 2 commits into from
Closed

Fix to output string of items rather than unicode of items. #39864

wants to merge 2 commits into from

Conversation

sean-m-sullivan
Copy link

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
  • Bugfix Pull Request
COMPONENT NAME

initi.py

ANSIBLE VERSION
ansible 2.5.2
  config file = /home/excalibrax/Dropbox/LinuxDocs/projects/ansible_testing/callback_plugins_git/testing_role/ansible.cfg
  configured module search path = [u'/home/excalibrax/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14 (default, Mar 14 2018, 13:36:31) [GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]

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:

  - name: add packages
    yum:
      name: "{{ item }}"
      state: present
    with_items:
       - httpd
       - perl

Output changes:

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'])

## 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'])
@ansibot ansibot added bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels May 8, 2018
@sean-m-sullivan
Copy link
Author

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?.

@ansibot
Copy link
Contributor

ansibot commented May 8, 2018

The test ansible-test sanity --test pylint [explain] failed with 1 error:

lib/ansible/plugins/callback/__init__.py:230:0: trailing-whitespace Trailing whitespace

The test ansible-test sanity --test pep8 [explain] failed with 2 errors:

lib/ansible/plugins/callback/__init__.py:230:9: E266 too many leading '#' for block comment
lib/ansible/plugins/callback/__init__.py:230:71: W291 trailing whitespace

click here for bot help

@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label May 8, 2018
Removed whitespace and extra #
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label May 8, 2018
@@ -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]
Copy link
Member

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

@ansibot
Copy link
Contributor

ansibot commented May 8, 2018

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

lib/ansible/plugins/callback/__init__.py:230:9: E265 block comment should start with '# '

click here for bot help

@mattclay
Copy link
Member

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:

2018-05-08 18:34:08 [WARNING]: Failure using method (v2_runner_item_on_ok) in callback plugin
2018-05-08 18:34:08 (<ansible.plugins.callback.default.CallbackModule object at 0x3909450>): 'int'
2018-05-08 18:34:08 object is not iterable

@mattclay mattclay added the ci_verified Changes made in this PR are causing tests to fail. label May 10, 2018
@ansibot ansibot added affects_2.6 This issue/PR affects Ansible v2.6 stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels May 18, 2018
@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html small_patch labels Jun 27, 2018
@ansibot ansibot added support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Sep 15, 2018
@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed support:community This issue/PR relates to code supported by the Ansible community. labels Nov 26, 2018
@ansible ansible locked and limited conversation to collaborators Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. ci_verified Changes made in this PR are causing tests to fail. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_contributor This PR is the first contribution by a new community member. small_patch stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants