---

- name: Install packages
  package:
    name: certbot
    state: installed

- name: Schedule renewal cert task
  cron:
    name: Renew Let's Encrypt certs
    job: 'certbot renew --allow-subset-of-names --quiet --renew-hook "systemctl reload nginx"'
    hour: "{{ ansible_date_time.hour }}"
    minute: "{{ ansible_date_time.minute }}"

---

- name: Install packages
  package:
    name: certbot
    state: installed

- name: Schedule renewal cert task
  cron:
    name: Renew Let's Encrypt certs
    job: 'certbot renew --allow-subset-of-names --quiet --renew-hook "systemctl reload nginx"'
    hour: "{{ ansible_date_time.hour }}"
    minute: "{{ ansible_date_time.minute }}"

- name: Remove old job
  cron:
    name: Renew Let's Encrypt certs
    state: absent
    user: "{{ os_user }}"

Remove old renewal job from schedule in ansible playbook
Remove old renewal job from schedule in ansible playbook
