ansible.builtin.symmetric_difference filter – different items from two lists


This filter plugin is part of ansible-core and included in all Ansible installations. In most cases, you can use the short plugin name symmetric_difference even without specifying the collections: keyword. However, we recommend you use the FQCN for easy linking to the plugin documentation and to avoid conflicting with other collections that may have the same filter plugin name.


  • Provide a unique list of all the elements unique to each list.


This describes the input of the filter, the value before | ansible.builtin.symmetric_difference.




list / elements=string / required

A list.

Keyword parameters

This describes keyword parameters of the filter. These are the values key1=value1, key2=value2 and so on in the following example: input | ansible.builtin.symmetric_difference(key1=value1, key2=value2, ...)




list / elements=string / required

A list.

See Also

See also

ansible.builtin.difference filter plugin

the difference of one list from another.

ansible.builtin.intersect filter plugin

intersection of lists.

ansible.builtin.union filter plugin

union of lists.

ansible.builtin.unique filter plugin

set of unique items of a list.


# return the elements of list1 not in list2 and the elements in list2 not in list1
# list1: [1, 2, 5, 1, 3, 4, 10]
# list2: [1, 2, 3, 4, 5, 11, 99]
{{ list1 | symmetric_difference(list2) }}
# => [10, 11, 99]

Return Value



Return value

list / elements=string

A unique list of the elements from two lists that are unique to each one.

Returned: success


  • Brian Coca (@bcoca)


Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.