---
- hosts: all
  become: true
  vars:
    mount_location_before: '/opt/test1'
    mount_location_after: ''
    volume_size: '3g'
  tags:
    - tests::lvm

  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: Create a LVM logical volume mounted at "{{ mount_location_before }}"
      include_role:
        name: redhat.rhel_system_roles.storage
      vars:
        storage_pools:
          - name: foo
            disks: "{{ unused_disks }}"
            volumes:
              - name: test1
                size: "{{ volume_size }}"
                mount_point: "{{ mount_location_before }}"

    - include_tasks: verify-role-results.yml

    - name: Change the mount location to "{{ mount_location_after }}"
      include_role:
        name: redhat.rhel_system_roles.storage
      vars:
        storage_pools:
          - name: foo
            disks: "{{ unused_disks }}"
            volumes:
              - name: test1
                size: "{{ volume_size }}"
                mount_point: "{{ mount_location_after }}"

    - include_tasks: verify-role-results.yml

    - name: Repeat the previous invocation to verify idempotence
      include_role:
        name: redhat.rhel_system_roles.storage
      vars:
        storage_pools:
          - name: foo
            disks: "{{ unused_disks }}"
            volumes:
              - name: test1
                size: "{{ volume_size }}"
                mount_point: "{{ mount_location_after }}"

    - include_tasks: verify-role-results.yml

    - name: Clean up
      include_role:
        name: redhat.rhel_system_roles.storage
      vars:
        storage_pools:
          - name: foo
            disks: "{{ unused_disks }}"
            state: absent
            volumes:
              - name: test1
                size: "{{ volume_size }}"
                mount_point: "{{ mount_location_after }}"

    - include_tasks: verify-role-results.yml
