Allow certificates to be expanded, now also for "webroot" method

This commit is contained in:
Andreas Motl 2022-01-25 00:04:48 +01:00
parent d62025267d
commit 95c899b215
3 changed files with 19 additions and 20 deletions

16
tasks/check-existence.yml Normal file
View File

@ -0,0 +1,16 @@
---
- 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.
set_fact:
cert_exists: true
when: cert_item.domains | sort | difference(item) == []
with_list: "{{ letsencrypt_certs.stdout_lines }}"

View File

@ -1,19 +1,5 @@
---
- 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.
set_fact:
cert_exists: true
when: cert_item.domains | sort | difference(item) == []
with_list: "{{ letsencrypt_certs.stdout_lines }}"
- include_tasks: check-existence.yml
- name: Ensure pre and post hook folders exist.
file:

View File

@ -1,8 +1,5 @@
---
- name: Check if certificate already exists.
stat:
path: /etc/letsencrypt/live/{{ cert_item.domains | first }}/cert.pem
register: letsencrypt_cert
- include_tasks: check-existence.yml
- name: Create webroot directory if it doesn't exist yet
file:
@ -11,4 +8,4 @@
- name: Generate new certificate if one doesn't exist.
command: "{{ certbot_create_command }}"
when: not letsencrypt_cert.stat.exists
when: not cert_exists