Bootstrap FreeKB - Ansible - Compare Differences between Lists
Ansible - Compare Differences between Lists

Updated:   |  Ansible articles

The difference filter can be used to compare differences between lists.

For example, the foo_list contains "pears" whereas the bar_list contains "oranges".

- hosts: localhost
    foo_list: [ "apple", "banana", "grapes", "pears"]
    bar_list: [ "apple", "banana", "grapes", "oranges"]
  - name: foo_list differences
      msg: "{{ foo_list | difference(bar_list) }}"

  - name: bar_list differences
      msg: "{{ bar_list | difference(foo_list) }}"


Should produce the following.

TASK [foo_list differences] 
ok: [localhost] => {
    "msg": [

TASK [bar_list differences] 
ok: [localhost] => {
    "msg": [


Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee


Add a Comment

Please enter 53f2b3 in the box below so that we can be sure you are a human.