---
- name: Cleanup - packages
  package:
    name: "cockpit*"
    state: absent
  when: not __cockpit_is_ostree | d(false)
  tags:
    - always
    - tests::cleanup

- name: Cleanup - services
  service:
    name: "{{ __cockpit_daemon }}"
    state: stopped
    enabled: false
  when: __cockpit_is_ostree | d(false)
  tags:
    - always
    - tests::cleanup

- name: Cleanup - find certificates
  find:
    paths: /etc/cockpit/ws-certs.d/
    file_type: any
    patterns: "*"
  register: certs_to_delete
  tags:
    - always
    - tests::cleanup

- name: Cleanup - certificates
  file:
    path: "{{ item.path }}"
    state: absent
  with_items: "{{ certs_to_delete.files }}"
  tags:
    - always
    - tests::cleanup

- name: Cleanup - config file
  file:
    path: /etc/cockpit/cockpit.conf
    state: absent
  tags:
    - always
    - tests::cleanup

- name: Cleanup - port customization
  file:
    path: /etc/systemd/system/cockpit.socket.d/
    state: absent
  tags:
    - always
    - tests::cleanup

- name: Cleanup - Reload systemd
  systemd:
    daemon_reload: true
  when: __cockpit_is_booted
  tags:
    - always
    - tests::cleanup
