---
- name: Test create raid volume and remove
  hosts: all
  become: true
  vars:
    storage_safe_mode: false
    storage_use_partitions: true
    mount_location: '/opt/test1'

  tasks:
    - name: Run the role
      include_role:
        name: linux-system-roles.storage

    - name: Mark tasks to be skipped
      set_fact:
        storage_skip_checks:
          - blivet_available
          - "{{ (lookup('env',
                        'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
                ternary('packages_installed', '') }}"
          - service_facts

    - name: Get unused disks
      include_tasks: get_unused_disk.yml
      vars:
        max_return: 2
        disks_needed: 2

    - name: Create a RAID0 device mounted on {{ mount_location }}
      include_role:
        name: linux-system-roles.storage
      vars:
        storage_volumes:
          - name: test1
            type: raid
            raid_level: raid0
            disks: "{{ unused_disks }}"
            mount_point: "{{ mount_location }}"

    - name: Verify role results
      include_tasks: verify-role-results.yml

    - name: Repeat the previous invocation to verify idempotence
      include_role:
        name: linux-system-roles.storage
      vars:
        storage_volumes:
          - name: test1
            type: raid
            raid_level: raid0
            disks: "{{ unused_disks }}"
            mount_point: "{{ mount_location }}"

    - name: Verify role results
      include_tasks: verify-role-results.yml

    - name: Remove the disk device created above
      include_role:
        name: linux-system-roles.storage
      vars:
        storage_volumes:
          - name: test1
            type: raid
            raid_level: raid0
            disks: "{{ unused_disks }}"
            mount_point: "{{ mount_location }}"
            state: absent

    - name: Verify role results
      include_tasks: verify-role-results.yml
