---
- name: Test remove resources
  hosts: localhost
  gather_facts: false
  tasks:

    - name: POSITIVE test -> Remove cluster
      infinidat.infinibox.infini_cluster:
        name: "{{ auto_prefix }}cluster_zero_hosts"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Remove cluster second cluster
      infinidat.infinibox.infini_cluster:
        name: "{{ auto_prefix }}cluster"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: IDEMPOTENT test -> Remove cluster second cluster again
      infinidat.infinibox.infini_cluster:
        name: "{{ auto_prefix }}cluster"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Remove mapping of volume from host
      infinidat.infinibox.infini_map:
        host: "{{ auto_prefix }}host"
        volume: "{{ auto_prefix }}vol"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Rescan with remove option after removing mapping
      ansible.builtin.shell: |
        rescan-scsi-bus.sh --remove
      become: true
      register: rescan
      failed_when: "rescan.rc != 0 and 'not found' not in rescan.stderr"
      changed_when: true

    - name: IDEMPOTENT test -> Remove mapping of volume from host again
      infinidat.infinibox.infini_map:
        host: "{{ auto_prefix }}host"
        volume: "{{ auto_prefix }}vol"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Remove host
      infinidat.infinibox.infini_host:
        name: "{{ auto_prefix }}host"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Remove second host
      infinidat.infinibox.infini_host:
        name: "{{ auto_prefix }}host2"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: IDEMPOTENT test -> Remove host again
      infinidat.infinibox.infini_host:
        name: "{{ auto_prefix }}host"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Remove export client for export
      infinidat.infinibox.infini_export_client:
        client: 20.20.20.20
        state: absent
        access_mode: "RO"
        export: "/{{ auto_prefix }}export"
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: IDEMPOTENT test -> Remove export client for export again
      infinidat.infinibox.infini_export_client:
        client: 20.20.20.20
        state: absent
        access_mode: "RO"
        export: "/{{ auto_prefix }}export"
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Remove export of file system
      infinidat.infinibox.infini_export:
        name: "/{{ auto_prefix }}export"
        filesystem: "{{ auto_prefix }}fs"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: IDEMPOTENT test -> Remove export of file system again
      infinidat.infinibox.infini_export:
        name: "/{{ auto_prefix }}export"
        filesystem: "{{ auto_prefix }}fs"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Remove file system
      infinidat.infinibox.infini_fs:
        name: "{{ auto_prefix }}fs_default"
        size: 1GB
        pool: "{{ auto_prefix }}pool"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Remove thick file system
      infinidat.infinibox.infini_fs:
        name: "{{ auto_prefix }}fs_thick"
        size: 1GB
        pool: "{{ auto_prefix }}pool"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Remove thin file system
      infinidat.infinibox.infini_fs:
        name: "{{ auto_prefix }}fs"
        size: 1GB
        pool: "{{ auto_prefix }}pool"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: IDEMPOTENT test -> Remove file system again
      infinidat.infinibox.infini_fs:
        name: "{{ auto_prefix }}fs"
        size: 1GB
        pool: "{{ auto_prefix }}pool"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Remove thin volume
      infinidat.infinibox.infini_vol:
        name: "{{ auto_prefix }}vol"
        pool: "{{ auto_prefix }}pool"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Remove thick volume
      infinidat.infinibox.infini_vol:
        name: "{{ auto_prefix }}vol_thick"
        pool: "{{ auto_prefix }}pool"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: IDEMPOTENT test -> Remove volume again
      infinidat.infinibox.infini_vol:
        name: "{{ auto_prefix }}vol"
        pool: "{{ auto_prefix }}pool"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Remove pool
      infinidat.infinibox.infini_pool:
        name: "{{ auto_prefix }}pool"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Remove snapshot
      infinidat.infinibox.infini_vol:
        name: "{{ auto_prefix }}vol_snap"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: IDEMPOTENT test -> Remove file system again from now missing pool
      infinidat.infinibox.infini_fs:
        name: "{{ auto_prefix }}fs"
        size: 1GB
        pool: "{{ auto_prefix }}pool"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Remove read only user
      infinidat.infinibox.infini_user:
        user_name: "{{ auto_prefix }}read_only_user"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Remove admin user
      infinidat.infinibox.infini_user:
        user_name: "{{ auto_prefix }}admin_user"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: POSITIVE test -> Remove pool admin user
      infinidat.infinibox.infini_user:
        user_name: "{{ auto_prefix }}pool_admin_user"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"

    - name: IDEMPOTENT test -> Remove pool admin user again
      infinidat.infinibox.infini_user:
        user_name: "{{ auto_prefix }}pool_admin_user"
        state: absent
        user: "{{ user }}"
        password: "{{ password }}"
        system: "{{ system }}"
