diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index bea8e66e450..3bbad05d2d2 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -38,6 +38,7 @@ import ansible.inventory from ansible import utils from ansible.utils import template from ansible.utils import check_conditional +from ansible.utils import string_functions from ansible import errors from ansible import module_common import poller @@ -742,6 +743,12 @@ class Runner(object): self.callbacks.on_unreachable(host, result.result) else: data = result.result + + # https://github.com/ansible/ansible/issues/4958 + if "stdout" in data and sys.stdout.isatty(): + if not string_functions.isprintable(data['stdout']): + data['stdout'] = '' + if 'item' in inject: result.result['item'] = inject['item'] diff --git a/lib/ansible/utils/string_functions.py b/lib/ansible/utils/string_functions.py new file mode 100644 index 00000000000..6d71c7bfa2e --- /dev/null +++ b/lib/ansible/utils/string_functions.py @@ -0,0 +1,7 @@ +def isprintable(instring): + #http://stackoverflow.com/a/3637294 + import string + printset = set(string.printable) + isprintable = set(instring).issubset(printset) + return isprintable +