From f5b6f52940bbea87daf35068a5f91e02f6b9af02 Mon Sep 17 00:00:00 2001
From: Dag Wieers <dag@wieers.com>
Date: Tue, 8 Mar 2016 17:33:29 +0100
Subject: [PATCH] Only show diff when the task actually induced a change

This implements solution #1 in the proposal #14860.

It only shows the diff if the task induced a change, which means that if the changed_when control overrides the task, not diff will be produced.
See #14860 for a rationale and the use-case.
---
 lib/ansible/plugins/callback/default.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/ansible/plugins/callback/default.py b/lib/ansible/plugins/callback/default.py
index 072eb5f4d25..e4f583db3d7 100644
--- a/lib/ansible/plugins/callback/default.py
+++ b/lib/ansible/plugins/callback/default.py
@@ -150,11 +150,11 @@ class CallbackModule(CallbackBase):
     def v2_on_file_diff(self, result):
         if result._task.loop and 'results' in result._result:
             for res in result._result['results']:
-                if 'diff' in res and res['diff']:
+                if 'diff' in res and res['diff'] and res.get('changed', False):
                     diff = self._get_diff(res['diff'])
                     if diff:
                         self._display.display(diff)
-        elif 'diff' in result._result and result._result['diff']:
+        elif 'diff' in result._result and result._result['diff'] and result._result.get('changed', False):
             diff = self._get_diff(result._result['diff'])
             if diff:
                 self._display.display(diff)