@@ -105,6 +105,14 @@ def handle_error(self, **kwargs):
105
105
def warn_callback (self , warning ):
106
106
self .display .warning (warning )
107
107
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
+
108
116
def run (self , terms , variables = None , ** kwargs ):
109
117
self .set_options (direct = kwargs )
110
118
@@ -114,10 +122,11 @@ def run(self, terms, variables=None, **kwargs):
114
122
warn_on_empty_api = self .get_option ("warn_on_empty_api" )
115
123
if not api_list :
116
124
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" )
118
127
else :
119
128
raise AnsibleLookupError ("Unable to find items in api_list" )
120
- return [ api_list ]
129
+ return self . create_present_list ( compare_list )
121
130
122
131
# Set Keys to keep for each list. Depending on type
123
132
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):
285
294
item .update ({"state" : "absent" })
286
295
# Combine Lists
287
296
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 )
290
298
compare_list .extend (difference )
291
299
# Return Compare list with difference attached
292
300
difference = compare_list
0 commit comments