yaml callback fails on python3

When the URI module returns complex JSON objects, the YAML callback
fails while trying to represent these objects.  The problem arises
because the filter method returns an iterator in Python 3, rather than a
str object.  Therefore, the str method expandtabs() is not available,
and the callback fails with the following error:

[WARNING]: Failure using method (v2_runner_on_failed) in callback plugin (<ansible.plugins.callback.yaml.CallbackModule object at 0x7f7c7ed8aa20>): 'filter' object has no attribute 'expandtabs'

Issue can be replicated by running this playbook:

- hosts: localhost
  gather_facts: false
  tasks:
    - uri:
        url: https://jsonplaceholder.typicode.com/posts

ansible-playbook tmp.yml -v

(cherry picked from commit 5839f07e0f)
This commit is contained in:
Jim Gu 2018-03-30 14:46:21 -04:00 committed by Matt Davis
parent b37facb234
commit 8473765ae6

View file

@ -47,7 +47,7 @@ def my_represent_scalar(self, tag, value, style=None):
# ...no trailing space
value = value.rstrip()
# ...and non-printable characters
value = filter(lambda x: x in string.printable, value)
value = ''.join(x for x in value if x in string.printable)
# ...tabs prevent blocks from expanding
value = value.expandtabs()
# ...and odd bits of whitespace