From 44bdc6fb79e8edbaf9101f3a7f57e9b02398a126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Moser?= Date: Sun, 30 Oct 2016 17:05:24 +0100 Subject: [PATCH] cloudstack: implement diff support (#18254) --- lib/ansible/module_utils/cloudstack.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/ansible/module_utils/cloudstack.py b/lib/ansible/module_utils/cloudstack.py index 5962c64ce79..d01fdcdb607 100644 --- a/lib/ansible/module_utils/cloudstack.py +++ b/lib/ansible/module_utils/cloudstack.py @@ -69,6 +69,10 @@ class AnsibleCloudStack(object): self.result = { 'changed': False, + 'diff' : { + 'before': dict(), + 'after': dict() + } } # Common returns, will be merged with self.returns @@ -149,6 +153,7 @@ class AnsibleCloudStack(object): def has_changed(self, want_dict, current_dict, only_keys=None): + result = False for key, value in want_dict.iteritems(): # Optionally limit by a list of keys @@ -172,18 +177,26 @@ class AnsibleCloudStack(object): current_dict[key] = complex(current_dict[key]) if value != current_dict[key]: - return True + self.result['diff']['before'][key] = current_dict[key] + self.result['diff']['after'][key] = value + result = True else: if self.case_sensitive_keys and key in self.case_sensitive_keys: if value != current_dict[key].encode('utf-8'): - return True + self.result['diff']['before'][key] = current_dict[key].encode('utf-8') + self.result['diff']['after'][key] = value + result = True # Test for diff in case insensitive way elif value.lower() != current_dict[key].encode('utf-8').lower(): - return True + self.result['diff']['before'][key] = current_dict[key].encode('utf-8') + self.result['diff']['after'][key] = value + result = True else: - return True - return False + self.result['diff']['before'][key] = None + self.result['diff']['after'][key] = value + result = True + return result def _get_by_key(self, key=None, my_dict=None):