Ansible - Set Model Filters
To get the difference in 2 lists (items from 1 that don't exist in 2):
{{ list1 | difference(list2) }}
Note: order matters, so you want {{ my_list_one | difference(my_list_two) }} {{ my_list_one | difference(my_list_two) }}
Since this is just a Jinja2 template, in pure Python, list - list is undefined.
In [1]: list1 = [1, 2, 3] In [2]: list2 = [3] In [3]: list1 - list2 --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-3-a683b4e3266d> in <module>() ----> 1 list1 - list2 TypeError: unsupported operand type(s) for -: 'list' and 'list'
Instead, you can browse the list
In [5]: [i for i in list1 if i not in list2] Out[5]: [1, 2]
source share