Ask Your Question
3

How can I check for differences or delta between two lists or dictionary keys in both directions (bi-directionally or symmetrically) using Ansible, without the need to create a new variable?

asked 2022-02-14 11:00:00 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-10-15 23:00:00 +0000

bukephalos gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-02-14 11:00:00 +0000

Seen: 13 times

Last updated: Oct 15 '21