Ansible – how to remove an item from a list?


I’d like to remove an item from a list, based on another list.

My second list:

How do I remove ‘item3’ from this list, to set a new fact?
I tried using ‘-‘ and union, but this does not end in the desired end result.

End goal:


Use difference not union:

An example playbook (note that you must also provide variable name to set_fact):

The result (excerpt):

Leave a Reply