---
- name: Ensure deploy hook folders exist.
  ansible.builtin.file:
    path: /etc/letsencrypt/renewal-hooks/deploy
    state: directory
    mode: "0755"
    owner: root
    group: root

- name: Create deploy hook to execute tasks post cert generatation.
  ansible.builtin.template:
    src: reload_services.j2
    dest: /etc/letsencrypt/renewal-hooks/deploy/reload_services.sh
    owner: root
    group: root
    mode: "0750"
  when:
    - certbot_create_reload_services is defined

- name: Create DNS {{ certbot_dns_plugin }} Plugin Credentials File.
  ansible.builtin.template:
    src: dns_plugin_credentials.j2
    dest: "{{ certbot_dns_credentials_file }}"
    owner: root
    group: root
    mode: "0600"
  when:
    - certbot_dns_plugin is in certbot_supported_dns_plugins

- name: Upload custom DNS Credentials file.
  ansible.builtin.copy:
    src: "{{ certbot_dns_credentials_custom_file }}"
    dest: "{{ certbot_dns_credentials_file }}"
    state: file
    mode: "0600"
    owner: root
    group: root
  when:
    - certbot_dns_plugin not in certbot_supported_dns_plugins
    - certbot_dns_credentials_custom_file is defined
