- name: Delete Remote Worker
  hosts: workers
  become: true
  tasks:
    # Disable and stop worker
    - name: Disable and stop worker
      ansible.builtin.systemd:
        name: nagios-mod-gearman-worker
        state: stopped
        enabled: false

    # Uninstall worker RPM
    - name: Uninstall worker RPM
      ansible.builtin.dnf:
        name: nagios-mod-gearman
        state: absent
      when: ansible_os_family == "RedHat"
    
    # Uninstall worker DEB
    - name: Uninstall worker DEB
      ansible.builtin.apt:
        name: nagios-mod-gearman-worker
        state: absent
      when: ansible_os_family == "Debian"

    - name: Uninstall tools DEB
      ansible.builtin.apt:
        name: nagios-mod-gearman-tools
        state: absent
      when: ansible_os_family == "Debian"

    # Uninstall plugin RPM
    - name: Uninstall plugin RPM
      ansible.builtin.dnf:
        name: nagiosxi-nagiosplugins
        state: absent
      when: ansible_os_family == "RedHat"

    # Uninstall plugin DEB
    - name: Uninstall plugin DEB
      ansible.builtin.apt:
        name: nagiosxi-nagiosplugins
        state: absent
      when: ansible_os_family == "Debian"

    # Reload systemd
    - name: Reload systemd daemon
      ansible.builtin.systemd:
        daemon_reload: yes
