# SPDX-License-Identifier: MIT
---
- name: Test import to Spark
  hosts: all
  vars:
    metrics_into_spark: true

  pre_tasks:
    - name: Stop test
      meta: end_host
      when: (ansible_distribution in ['RedHat'] and
             (ansible_facts['distribution_version'] is version('8.4', '<'))) or
             ansible_distribution not in ['Fedora', 'RedHat']

    - name: Save state of services
      import_tasks: get_services_state.yml

  tasks:
    - name: Run test
      block:
        - name: Run the role
          include_role:
            name: linux-system-roles.metrics
            public: true

        - name: Check if import to Spark works
          include_tasks: check_into_spark.yml

        - name: Flush handlers
          meta: flush_handlers

      rescue:
        - name: Handle failure case
          include_tasks: handle_test_failure.yml

      always:
        - name: Restore state of services
          import_tasks: restore_services_state.yml
