And I would think the former would be more preferable as it is more generally applicable (would work with all modules).
I think of “with_items” as being analogous to a for loop in most programming languages. So I guess that means the feature that I am wishing I had here is analogous to a “continue” statement in those same programming languages.
ah, thought you wanted an empty string, misread from your example.
you'll have to use a when condition or dynamically construct the list,
there is no way to have a list item return a 'delete this item', even
None would return an empty element, but still and element.
list:
- 1
- 2
- <whatever>
is already a list of 3 items, no value of <whatever> can remove the -
in front of it as it is processed by YAML and <whatever> is by jinja2,
when its already a 3 element list.
example of dynamic list
with_items: {{"[1,2]|union( condition|ternary(['stuff'], ))"}}
it uses union to add elements from either list with 'stuff' or empty
list, which leaves the original 'unchanged'