@@ -223,18 +223,28 @@ def _populate(self, client):
223
223
#sys.exit()
224
224
for host in hosts :
225
225
break_flag = False
226
- for filter in self .filters :
227
- key = filter .get ("key" )
228
- expected_value = filter .get ("value" )
226
+ for filter_config in self .filters :
227
+ key = filter_config .get ("key" )
228
+ expected_value = filter_config .get ("value" )
229
229
try :
230
- value = self ._compose (key , host )
231
- if value != expected_value :
230
+ actual_value = self ._compose (key , host )
231
+ # Key is defined, and we have its actual_value
232
+ if actual_value != expected_value :
233
+ break_flag = True # Value mismatch, so host fails this filter
234
+ break
235
+ # If actual_value == expected_value, this filter is matched. Continue to next filter.
236
+ except (jinja2 .exceptions .UndefinedError , ansible .errors .AnsibleUndefinedVariable ):
237
+ # Key is undefined in the host data.
238
+ # Check if the filter expected it to be undefined.
239
+ # We assume 'None' (from YAML null) in the filter's 'value' means "should be undefined".
240
+ if expected_value is None :
241
+ # Filter expects key to be undefined, and it is. This filter is matched.
242
+ # Continue to the next filter for this host.
243
+ pass
244
+ else :
245
+ # Filter expects a concrete value, but key is undefined. This filter is NOT matched.
232
246
break_flag = True
233
247
break
234
- except jinja2 .exceptions .UndefinedError :
235
- break
236
- except ansible .errors .AnsibleUndefinedVariable :
237
- break
238
248
239
249
if break_flag is True :
240
250
continue
0 commit comments