- name: Stop and disable the KF2 service
  systemd:
    name: kf2
    state: stopped
    enabled: no
  when: ansible_facts.services["kf2.service"] is defined

- name: Stop and disable the KF2 autokick service
  systemd:
    name: kf2autokick
    state: stopped
    enabled: no
  when: ansible_facts.services["kf2autokick.service"] is defined

- name: Remove KF2 services
  file:
    path: "/etc/systemd/system/{{ item }}"
    state: absent
  loop:
  - kf2.service
  - kf2autokick.service
  notify: Reload systemd configuration

- name: Remove service extra files
  file:
    path: /etc/systemd/system/kf2.service.d
    state: absent

- meta: flush_handlers

- name: Check the state of system services
  service_facts:

- name: Stop and disable the KF2 service
  systemd:
    name: kf2
    state: stopped
    enabled: no
  when: ansible_facts.services["kf2.service"] is defined

- name: Stop and disable the KF2 autokick service
  systemd:
    name: kf2autokick
    state: stopped
    enabled: no
  when: ansible_facts.services["kf2autokick.service"] is defined

- name: Remove KF2 services
  file:
    path: "/etc/systemd/system/{{ item }}"
    state: absent
  loop:
  - kf2.service
  - kf2autokick.service
  notify: Reload systemd configuration

- name: Remove service extra files
  file:
    path: /etc/systemd/system/kf2.service.d
    state: absent

- meta: flush_handlers

Load service facts before using them
Load service facts before using them
