# SPDX-License-Identifier: MIT
---
- name: Test import from Spark
  hosts: all
  vars:
    metrics_from_spark: true

  pre_tasks:
    - name: Stop test
      meta: end_host
      when: (ansible_distribution in ['RedHat', 'CentOS'] and
             ansible_distribution_major_version | int < 7) or
             ansible_distribution not in ['Fedora', 'RedHat', 'CentOS']

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

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

        - name: Check if import from Spark works
          include_tasks: check_from_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
