Skip to content

Commit c39d834

Browse files
RickmargesMarges, RSY (Rick)
and
Marges, RSY (Rick)
authored
Fix the diff functionality when using with_present (#615)
Co-authored-by: Marges, RSY (Rick) <rick.marges@achmea.nl>
1 parent d499e5b commit c39d834

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

plugins/lookup/controller_object_diff.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ def handle_error(self, **kwargs):
105105
def warn_callback(self, warning):
106106
self.display.warning(warning)
107107

108+
def create_present_list(self, compare_list):
109+
if not compare_list:
110+
return [compare_list]
111+
112+
for item in compare_list:
113+
item.update({"state": "present"})
114+
return compare_list
115+
108116
def run(self, terms, variables=None, **kwargs):
109117
self.set_options(direct=kwargs)
110118

@@ -114,10 +122,11 @@ def run(self, terms, variables=None, **kwargs):
114122
warn_on_empty_api = self.get_option("warn_on_empty_api")
115123
if not api_list:
116124
if warn_on_empty_api:
117-
self._display.warning("Skipping, did not find items in api_list")
125+
if not compare_list:
126+
self._display.warning("Skipping, did not find items in neither api_list nor compare_list")
118127
else:
119128
raise AnsibleLookupError("Unable to find items in api_list")
120-
return [api_list]
129+
return self.create_present_list(compare_list)
121130

122131
# Set Keys to keep for each list. Depending on type
123132
if api_list[0]["type"] == "organization" or api_list[0]["type"] == "credential_type" or api_list[0]["type"] == "instance_group":
@@ -285,8 +294,7 @@ def run(self, terms, variables=None, **kwargs):
285294
item.update({"state": "absent"})
286295
# Combine Lists
287296
if self.get_option("with_present"):
288-
for item in compare_list_reduced:
289-
item.update({"state": "present"})
297+
self.create_present_list(compare_list_reduced)
290298
compare_list.extend(difference)
291299
# Return Compare list with difference attached
292300
difference = compare_list

0 commit comments

Comments
 (0)