allow certificates to be expanded

This commit is contained in:
Yannick Markus 2020-06-26 17:26:36 +02:00 committed by Andreas Motl
parent c6297ddebb
commit a4a25f8139
2 changed files with 16 additions and 5 deletions

View File

@ -35,7 +35,7 @@ certbot_create_command: >-
--email {{ cert_item.email | default(certbot_admin_email) }}
{{ '--webroot-path ' if certbot_create_method == 'webroot' else '' }}
{{ cert_item.webroot | default(certbot_webroot) if certbot_create_method == 'webroot' else '' }}
-d {{ cert_item.domains | join(',') }}
--domains {{ cert_item.domains | join(',') }} --expand
{{ '--pre-hook /etc/letsencrypt/renewal-hooks/pre/stop_services'
if certbot_create_standalone_stop_services
else '' }}

View File

@ -1,8 +1,19 @@
---
- name: Get installed certificates.
shell: |
{{ certbot_script }} certificates | grep "Domains:" | awk '{ gsub(/ Domains: /,""); print }'
changed_when: false
register: letsencrypt_certs
- name: Set cert_exists to false (to check if cert exists).
set_fact:
cert_exists: false
- name: Check if certificate already exists.
stat:
path: /etc/letsencrypt/live/{{ cert_item.domains | first | replace('*.', '') }}/cert.pem
register: letsencrypt_cert
set_fact:
cert_exists: true
when: cert_item.domains | sort | difference(item) == []
with_list: "{{ letsencrypt_certs.stdout_lines }}"
- name: Ensure pre and post hook folders exist.
file:
@ -39,4 +50,4 @@
- name: Generate new certificate if one doesn't exist.
command: "{{ certbot_create_command }}"
when: not letsencrypt_cert.stat.exists
when: not cert_exists