---
- hosts: all
  become: true
  vars:
    storage_safe_mode: false
    mount_location: '/opt/test1'
    volume_size: '5g'

  tasks:
    - include_role:
        name: redhat.rhel_system_roles.storage

    - name: Mark tasks to be skipped
      set_fact:
        storage_skip_checks:
          - blivet_available
          - packages_installed
          - service_facts

    - include_tasks: get_unused_disk.yml
      vars:
        min_size: "{{ volume_size }}"
        max_return: 1

    - name: set label
      include_role:
        name: redhat.rhel_system_roles.storage
      vars:
        storage_volumes:
          - name: test1
            type: disk
            mount_point: "{{ mount_location }}"
            fs_type: ext4
            disks: "{{ unused_disks }}"
            fs_label: label

    - include_tasks: verify-role-results.yml

    - name: relabel
      include_role:
        name: redhat.rhel_system_roles.storage
      vars:
        storage_volumes:
          - name: test1
            type: disk
            mount_point: "{{ mount_location }}"
            fs_type: ext4
            disks: "{{ unused_disks }}"
            fs_label: relabel

    - include_tasks: verify-role-results.yml

    - name: run relabel again to verify idempotence
      include_role:
        name: redhat.rhel_system_roles.storage
      vars:
        storage_volumes:
          - name: test1
            type: disk
            mount_point: "{{ mount_location }}"
            fs_type: ext4
            disks: "{{ unused_disks }}"
            fs_label: relabel

    - name: check for idempotency
      assert:
        that: not blivet_output.changed
        msg: "Volume relabeling is not idempotent."

    - include_tasks: verify-role-results.yml

    - name: Clean up
      include_role:
        name: redhat.rhel_system_roles.storage
      vars:
        storage_volumes:
          - name: test1
            type: disk
            mount_point: "{{ mount_location }}"
            disks: "{{ unused_disks }}"
            state: absent

    - include_tasks: verify-role-results.yml
