- name: Validate default kernel is booted
  ansible.builtin.include_role:
    name: initramfs
    tasks_from: preflight
  when: snapshot_create_boot_backup

- name: Verify that all volumes exist
  ansible.builtin.include_tasks: verify_volume_exists.yml
  loop: "{{ snapshot_create_volumes }}"

- name: Verify that there are no existing snapshots
  ansible.builtin.include_tasks: verify_no_existing_snapshot.yml
  loop: "{{ snapshot_create_volumes }}"

- name: Verify that there is enough storage space
  ansible.builtin.script: check.py snapshots '{{ snapshot_create_volumes | to_json }}'
  args:
    executable: "{{ ansible_python.executable }}"
  register: snapshot_create_check_status
  failed_when: false
  changed_when: false

- name: Store check return in case of failure
  ansible.builtin.set_fact:
    snapshot_create_check_failure_json: "{{ snapshot_create_check_status.stdout | from_json }}"
  when: snapshot_create_check_status.rc != 0

- name: Assert results
  ansible.builtin.assert:
    that: snapshot_create_check_status.rc == 0
    fail_msg: Not enough space in the Volume Groups to create the requested snapshots
    success_msg: The Volume Groups have enough space to create the requested snapshots
