diff --git a/roles/webgateway/tasks/main.yaml b/roles/webgateway/tasks/main.yaml index 2b10fa4..cc776df 100644 --- a/roles/webgateway/tasks/main.yaml +++ b/roles/webgateway/tasks/main.yaml @@ -32,15 +32,29 @@ state: restarted enabled: yes -#- name: Generate certificate for all proxied domains -# command: -# cmd: certbot certonly --nginx -d {{item.domain}} -# with_items: "{{ proxy }}" -# -#- name: Generate certificate for all static sites -# command: -# cmd: certbot certonly --nginx -d {{item.domain}} -# with_items: "{{ static }}" +- name: "Check if proxy domains have certificate available" + stat: + path: "/etc/letsencrypt/live/{{ item.domain }}" + register: "{{ item.domain }}_available" + with_items: "{{ proxy }}" + +- name: "Check if statically served domains have certificate available" + stat: + path: "/etc/letsencrypt/live/{{ item.domain }}" + register: "{{ item.domain }}_available" + with_items: "{{ static }}" + +- name: Generate certificate for all proxied domains + command: + cmd: certbot certonly --nginx -d {{item.domain}} + with_items: "{{ proxy }}" + when: not {{ item.domain }}_available.stat.exists + +- name: Generate certificate for all static sites + command: + cmd: certbot certonly --nginx -d {{item.domain}} + with_items: "{{ static }}" + when: not {{ item.domain }}_available.stat.exists - name: "Generate certbot script" ansible.builtin.template: @@ -117,4 +131,4 @@ ansible.builtin.file: path: "{{ item.directory}}/.git" state: absent - with_items: "{{ static }}" \ No newline at end of file + with_items: "{{ static }}"