Search arrays inside ansible msg output

  ansible_libvirt_pools:
    default:
      autostart: 'yes'
      path: /var/lib/libvirt/images
      persistent: 'yes'
      size_available: '60503101440'
      size_total: '75125227520'
      size_used: '14622126080'
      state: active
      status: running
      type: dir
      uuid: 5f6e9ba1-6a50-4313-9aa6-0981448aff0a
      volume_count: 5
      volumes:
      - centos-8-stream.raw
      - ubuntu-20.04-server-cloudimg-amd64.img
      - ubuntu-server-20.04.raw
      - vyos-1.4-rolling-202201080317-amd64.iso
      - CentOS-Stream-GenericCloud-8-20201019.1.x86_64.qcow2
    infra0_pool_0:
      autostart: 'yes'
      format: lvm2
      path: /dev/almalinux_images1
      persistent: 'yes'
      size_available: '11704318558208'
      size_total: '11998523817984'
      size_used: '294205259776'
      state: active
      status: running
      type: logical
      uuid: 62882128-003d-472c-ac89-d0118cc992c6
      volume_count: 6
      volumes:
      - admin0.admin_base_vol
      - test01.test_base_vol
      - test00.test_base_vol
      - root
      - vyos0
      - swap

Q: "How to search a specific volumes array to see if a value already exists."

A: For example, given the list of volumes that should exist

  vm_volumes: [swap, export]

the task below

    - debug:
        msg: "Missing volumes in {{ item.key }}: {{ _missing }}"
      loop: "{{ ansible_libvirt_pools|dict2items }}"
      vars:
        _missing: "{{ vm_volumes|difference(item.value.volumes) }}"

gives (abridged)

  msg: 'Missing volumes in default: [''swap'', ''export'']'
  msg: 'Missing volumes in infra0_pool_0: [''export'']'

If you want to find existing volumes the task below

    - debug:
        msg: "Present volumes in {{ item.key }}: {{ _present }}"
      loop: "{{ ansible_libvirt_pools|dict2items }}"
      vars:
        _present: "{{ vm_volumes|intersect(item.value.volumes) }}"

gives (abridged)

  msg: 'Present volumes in default: []'
  msg: 'Present volumes in infra0_pool_0: [''swap'']'