# SPDX-License-Identifier: MIT
---
- name: Test configuration of webhook notification
  hosts: all
  vars:
    __test_webhook: https://example.com:4242/endpoint
    metrics_webhook_endpoint: "{{ __test_webhook }}"

  pre_tasks:
    - name: Skip test if not supported by platform
      meta: end_host
      when: (ansible_distribution in ['RedHat', 'CentOS'] and (ansible_facts['distribution_version'] is version('9.3', '<'))) 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 role
          include_role:
            name: fedora.linux_system_roles.metrics
            public: true

        - name: Check basic services and the webhook endpoint
          include_tasks: "{{ item }}"
          loop:
            - check_pcp.yml
            - check_pmie.yml
            - check_notification.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
