From 28169492f9edaafdcc62e0d69d9b975cf56064bb Mon Sep 17 00:00:00 2001 From: Tobias Wolf Date: Wed, 3 Feb 2016 16:14:22 +0100 Subject: [PATCH] Do not insert newlines when diff is empty --- lib/ansible/plugins/callback/__init__.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/ansible/plugins/callback/__init__.py b/lib/ansible/plugins/callback/__init__.py index 3a1e5f8caee..1fa6c03753b 100644 --- a/lib/ansible/plugins/callback/__init__.py +++ b/lib/ansible/plugins/callback/__init__.py @@ -127,14 +127,22 @@ class CallbackBase: after_header = "after: %s" % diff['after_header'] else: after_header = 'after' - differ = difflib.unified_diff(to_unicode(diff['before']).splitlines(True), to_unicode(diff['after']).splitlines(True), before_header, after_header, '', '', 10) - ret.extend(list(differ)) - ret.append('\n') + differ = difflib.unified_diff(to_unicode(diff['before']).splitlines(True), + to_unicode(diff['after']).splitlines(True), + fromfile=before_header, + tofile=after_header, + fromfiledate='', + tofiledate='', + n=10) + difflines = list(differ) + if difflines: + ret.extend(difflines) + ret.append('\n') if 'prepared' in diff: ret.append(to_unicode(diff['prepared'])) except UnicodeDecodeError: ret.append(">> the files are different, but the diff library cannot compare unicode strings\n\n") - return u"".join(ret) + return u''.join(ret) def _get_item(self, result): if result.get('_ansible_no_log', False):