---
- name: Check if certificate already exists.
  ansible.builtin.stat:
    path: /etc/letsencrypt/live/{{ cert_item.domains | first | replace('*.', '') }}/cert.pem
  register: letsencrypt_cert

- name: Delete Certificate
  ansible.builtin.command: "{{ certbot_delete_command }}"
  when:
    - letsencrypt_cert.stat.exists

- name: Make sure certificate directory is removed
  ansible.builtin.file:
    path: /etc/letsencrypt/live/{{ cert_item.domains | first | replace('*.', '') }}
    state: absent
  when:
    - letsencrypt_cert.stat.exists
