---
- name: Set common facts
  ansible.builtin.import_tasks: tasks/set-default-facts.yml

- name: Deploy {{ svc.name }}
  vars:
    svc: "{{ lego_svc }}"
    env: "{{ lego_env }}"
    json: "{{ vault_acmedns_registered | acmedns_to_lego }}"
    compose: "{{ lego_compose }}"
  block:
    - name: Import prepare tasks for common service
      ansible.builtin.import_tasks: tasks/prepare-common-service.yml

    - name: Create _certificates directory
      ansible.builtin.file:
        path: "{{ certificates_path }}"
        state: directory
        mode: "0755"

    - name: Import tasks specific to the config directory
      ansible.builtin.import_tasks: config.yml
    - name: Import tasks specific to lego.d
      ansible.builtin.import_tasks: lego.d.yml
    - name: Import tasks specific to systemd
      ansible.builtin.import_tasks: systemd.yml

    - name: Copy the run script
      ansible.builtin.copy:
        src: "lego.sh"
        dest: "{{ (service_path, 'lego.sh') | path_join }}"
        mode: "0755"

    - name: Import tasks create a service.env file
      ansible.builtin.import_tasks: tasks/steps/template-service-env.yml