Ansible-newbie here.
I am struggling with understanding how to check if a value exists in an array returned from a previous task. Im trying to search if a volume exists in any array of volumes returned from a search:
- name: Get volume pools data
community.libvirt.virt_pool:
command: facts
changed_when: false
- debug: msg="{{ ansible_libvirt_pools }}.stdout_lines"
this returns output like this:
ok: [server] => {
"msg": "{'default': {'status': 'running', 'size_total': '75125227520', 'size_used': '14622126080', 'size_available': '60503101440', 'autostart': 'yes', 'persistent': 'yes', 'state': 'active', 'path': '/var/lib/libvirt/images', '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': {'status': 'running', 'size_total': '11998523817984', 'size_used': '294205259776', 'size_available': '11704318558208', 'autostart': 'yes', 'persistent': 'yes', 'state': 'active', 'path': '/dev/almalinux_images1', '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'], 'format': 'lvm2'}}.stdout_lines"
}
I need help understanding how to search a specific volumes array to see if a value already exists, and to ignore:
- name: Create VM volume
command: |
virsh vol-create-as {{ pool_name }} {{ vm_volume }} {{ vm_size }}
when {{ vm_volume}} not in ansible_libvirt_pools.{{ pool_name }}.volumes
Would appreciate any help on how to do this correctly. Im getting warnings on Jinja templating for the 'when' statement, and I don't think its working as expected.