# SPDX-License-Identifier: MIT
---
- name: Test BPFTrace with SASL auth
  hosts: all
  vars:
    __test_uname: pcptest
    metrics_from_bpftrace: true
    metrics_username: "{{ __test_uname }}"
    metrics_password: "{{ pcptest_pw }}"
  # test not to install selinux and firewall, explicitly
    metrics_manage_firewall: false
    metrics_manage_selinux: false

  pre_tasks:
    - name: Stop test
      meta: end_host
      when: (ansible_distribution in ['RedHat', 'CentOS'] and ansible_distribution_major_version | int < 8) 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 if BPFTrace & SASL works
          include_tasks: "{{ item }}"
          loop:
            - check_bpftrace.yml
            - check_sasl.yml
            - check_firewall_selinux.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
