---
- name: Try to get flavor facts
  os_flavor_facts:
    name: "{{ item.flavor }}"
  register: flavor_result

- name: Check that flavor is available
  assert:
    that: "flavor_result.ansible_facts.openstack_flavors"
    msg: "Flavor {{ item.flavor }} is not available."

- name: Try to get image facts
  os_image_facts:
    image: "{{ item.image }}"
  register: image_result

- name: Check that image is available
  assert:
    that: "image_result.ansible_facts.openstack_image"
    msg: "Image {{ item.image }} is not available."

- name: Verify flavor meets image requirements
  assert:
    that:
    - "flavor_result.ansible_facts.openstack_flavors[0].ram >= image_result.ansible_facts.openstack_image.min_ram"
    - "flavor_result.ansible_facts.openstack_flavors[0].disk >= image_result.ansible_facts.openstack_image.min_disk"
    msg: "Flavor {{ item.flavor }} does not meet the size requirements for image {{ item.image }}."
