diff --git a/tasks/configure.yml b/tasks/configure.yml index 348b040..9f6b348 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -27,19 +27,6 @@ - ssl - mpm_prefork -- name: Stop Apache - service: - name: apache2 - state: stopped - -- name: Ensure SSL certificate exists - shell: "certbot certonly --agree-tos --email certs@susurrando.com -n --standalone -d {{ item.vhostname }}" - args: - creates: "/etc/letsencrypt/archive/{{ item.vhostname }}" - when: - - "'ssl' in item" - - item['ssl'] - with_items: "{{ vhosts }}" - name: Ensure default vhost root exists file: @@ -67,11 +54,6 @@ notify: - Restart Apache -- name: Start Apache - service: - name: apache2 - state: started - - name: Ensure Apache modules are enabled community.general.apache2_module: state: present diff --git a/tasks/configure_certificate.yml b/tasks/configure_certificate.yml new file mode 100644 index 0000000..b8bae8b --- /dev/null +++ b/tasks/configure_certificate.yml @@ -0,0 +1,19 @@ +--- +- name: Stop Apache + service: + name: apache2 + state: stopped + +- name: Ensure SSL certificate exists + shell: "certbot certonly --agree-tos --email certs@susurrando.com -n --standalone -d {{ item.vhostname }}" + args: + creates: "/etc/letsencrypt/archive/{{ item.vhostname }}" + when: + - "'ssl' in item" + - item['ssl'] + with_items: "{{ vhosts }}" + +- name: Start Apache + service: + name: apache2 + state: started diff --git a/tasks/main.yml b/tasks/main.yml index cbe813e..6b13099 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,5 +1,15 @@ --- - name: Ensure installation include_tasks: install.yml + - name: Ensure configuration - include_tasks: configure.yml \ No newline at end of file + include_tasks: configure.yml + +- name: Get certificate file + stat: + path: "/etc/letsencrypt/archive/{{ item.vhostname }}" + register: certificate_folder + +- name: Ensure certificate is created + include_tasks: configure_certificate.yml + when: not certificate_folder.stat.exists