1 | initial version |
You can use the symmetric_difference
filter in Ansible to check for differences or delta between two lists or dictionary keys in both directions (bi-directionally or symmetrically) without the need to create a new variable. Here's an example:
- name: Check for differences
debug:
var: list1|symmetric_difference(list2)
In this example, list1
and list2
are the two lists that you want to check for differences. The symmetric_difference
filter will return the symmetric difference between the two lists, i.e., the elements that are present in one list but not in the other.
You can also use this filter to check for differences between two dictionary keys by specifying the keys:
- name: Check for differences
debug:
var: dict1.key1|symmetric_difference(dict2.key2)
In this example, dict1.key1
and dict2.key2
are the two dictionary keys that you want to check for differences. The symmetric_difference
filter will return the symmetric difference between the values of these keys in the two dictionaries.