From 8edcca0ef5a0dea6df6c65a9d8c407965c7a4f74 Mon Sep 17 00:00:00 2001
From: George Christou <gechrr@gmail.com>
Date: Mon, 15 Feb 2016 22:18:59 +0000
Subject: [PATCH 1/2] Add simple --diff colour support

---
 lib/ansible/plugins/callback/__init__.py | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/ansible/plugins/callback/__init__.py b/lib/ansible/plugins/callback/__init__.py
index 1fa6c03753b..ce028dc2793 100644
--- a/lib/ansible/plugins/callback/__init__.py
+++ b/lib/ansible/plugins/callback/__init__.py
@@ -28,6 +28,7 @@ from ansible.compat.six import string_types
 
 from ansible import constants as C
 from ansible.vars import strip_internal_keys
+from ansible.utils.color import stringc
 from ansible.utils.unicode import to_unicode
 
 try:
@@ -134,9 +135,17 @@ class CallbackBase:
                                                       fromfiledate='',
                                                       tofiledate='',
                                                       n=10)
-                        difflines = list(differ)
-                        if difflines:
-                            ret.extend(difflines)
+                        has_diff = False
+                        for line in differ:
+                            has_diff = True
+                            if line.startswith('-'):
+                                line = stringc(line, 'red')
+                            elif line.startswith('+'):
+                                line = stringc(line, 'green')
+                            elif line.startswith('@@'):
+                                line = stringc(line, 'cyan')
+                            ret.append(line)
+                        if has_diff:
                             ret.append('\n')
                     if 'prepared' in diff:
                         ret.append(to_unicode(diff['prepared']))

From 56239ee347c8cf156466c06975055faeeca86abe Mon Sep 17 00:00:00 2001
From: George Christou <gechrr@gmail.com>
Date: Wed, 17 Feb 2016 10:10:07 +0000
Subject: [PATCH 2/2] Make --diff colours configurable

---
 lib/ansible/constants.py                 |  3 +++
 lib/ansible/plugins/callback/__init__.py | 10 +++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py
index d277c717b54..6dad199e9b5 100644
--- a/lib/ansible/constants.py
+++ b/lib/ansible/constants.py
@@ -278,6 +278,9 @@ COLOR_SKIP        = get_config(p, 'colors', 'skip', 'ANSIBLE_COLOR_SKIP', 'cyan'
 COLOR_UNREACHABLE = get_config(p, 'colors', 'unreachable', 'ANSIBLE_COLOR_UNREACHABLE', 'bright red')
 COLOR_OK          = get_config(p, 'colors', 'ok', 'ANSIBLE_COLOR_OK', 'green')
 COLOR_CHANGED     = get_config(p, 'colors', 'ok', 'ANSIBLE_COLOR_CHANGED', 'yellow')
+COLOR_DIFF_ADD    = get_config(p, 'colors', 'diff_add', 'ANSIBLE_COLOR_DIFF_ADD', 'green')
+COLOR_DIFF_REMOVE = get_config(p, 'colors', 'diff_remove', 'ANSIBLE_COLOR_DIFF_REMOVE', 'red')
+COLOR_DIFF_LINES  = get_config(p, 'colors', 'diff_lines', 'ANSIBLE_COLOR_DIFF_LINES', 'cyan')
 
 # non-configurable things
 MODULE_REQUIRE_ARGS       = ['command', 'shell', 'raw', 'script']
diff --git a/lib/ansible/plugins/callback/__init__.py b/lib/ansible/plugins/callback/__init__.py
index ce028dc2793..58904420af0 100644
--- a/lib/ansible/plugins/callback/__init__.py
+++ b/lib/ansible/plugins/callback/__init__.py
@@ -138,12 +138,12 @@ class CallbackBase:
                         has_diff = False
                         for line in differ:
                             has_diff = True
-                            if line.startswith('-'):
-                                line = stringc(line, 'red')
-                            elif line.startswith('+'):
-                                line = stringc(line, 'green')
+                            if line.startswith('+'):
+                                line = stringc(line, C.COLOR_DIFF_ADD)
+                            elif line.startswith('-'):
+                                line = stringc(line, C.COLOR_DIFF_REMOVE)
                             elif line.startswith('@@'):
-                                line = stringc(line, 'cyan')
+                                line = stringc(line, C.COLOR_DIFF_LINES)
                             ret.append(line)
                         if has_diff:
                             ret.append('\n')