From 8473765ae6bbc672d9400030044145024796e9e0 Mon Sep 17 00:00:00 2001 From: Jim Gu Date: Fri, 30 Mar 2018 14:46:21 -0400 Subject: [PATCH] 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 (): '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) --- lib/ansible/plugins/callback/yaml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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