---
- name: Find unused disks in the system
  redhat.rhel_system_roles.find_unused_disk:
    min_size: "{{ min_size | d(omit) }}"
    max_size: "{{ max_size | d(omit) }}"
    max_return: "{{ max_return | d(omit) }}"
    with_interface: "{{ storage_test_use_interface | d(omit) }}"
  register: unused_disks_return

- name: Set unused_disks if necessary
  set_fact:
    unused_disks: "{{ unused_disks_return.disks }}"
  when: "'Unable to find unused disk' not in unused_disks_return.disks"

- name: Exit playbook when there's not enough unused disks in the system
  fail:
    msg: "Unable to find enough unused disks. Exiting playbook."
  when: unused_disks is undefined or unused_disks|length < disks_needed|default(1)

- name: Print unused disks
  debug:
    var: unused_disks
