diff options
author | Jim Gu <heming.gu@mercurygate.com> | 2018-03-30 14:46:21 -0400 |
---|---|---|
committer | Matt Davis <mrd@redhat.com> | 2018-04-18 10:00:44 -0700 |
commit | 8473765ae6bbc672d9400030044145024796e9e0 (patch) | |
tree | dcac5daf15cf6f21e5f03ab25d2ea43c8464dc0d | |
parent | b37facb2349e642c87af5bcd3daa7e4628747869 (diff) | |
download | ansible-8473765ae6bbc672d9400030044145024796e9e0.tar.gz |
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 5839f07e0f61efd0e2dd5798467d8377b0fab64c)
-rw-r--r-- | lib/ansible/plugins/callback/yaml.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/ansible/plugins/callback/yaml.py b/lib/ansible/plugins/callback/yaml.py index e8a23ea4d5..971193a237 100644 --- a/lib/ansible/plugins/callback/yaml.py +++ b/lib/ansible/plugins/callback/yaml.py @@ -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 |