allow certificates to be expanded

This commit is contained in:
Yannick Markus 2020-06-26 17:26:36 +02:00
parent b3a886e9ee
commit e5c0dc1541
2 changed files with 19 additions and 8 deletions

View File

@ -18,7 +18,7 @@ certbot_certs: []
# - domains:
# - example3.com
certbot_create_command: >-
{{ certbot_script }} certonly --standalone --noninteractive --agree-tos
{{ certbot_script }} certonly --standalone --noninteractive --expand --agree-tos
--email {{ cert_item.email | default(certbot_admin_email) }}
-d {{ cert_item.domains | join(',') }}

View File

@ -1,23 +1,34 @@
---
- name: Check if certificate already exists.
stat:
path: /etc/letsencrypt/live/{{ cert_item.domains | first | replace('*.', '') }}/cert.pem
register: letsencrypt_cert
- name: Get installed certs.
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 the cert exists.
set_fact:
cert_exists: true
when: cert_item.domains | sort | difference(item) == []
with_list: "{{ letsencrypt_certs.stdout_lines }}"
- name: Stop services to allow certbot to generate a cert.
service:
name: "{{ item }}"
state: stopped
when: not letsencrypt_cert.stat.exists
when: not cert_exists
with_items: "{{ certbot_create_standalone_stop_services }}"
- name: Generate new certificate if one doesn't exist.
command: "{{ certbot_create_command }}"
when: not letsencrypt_cert.stat.exists
when: not cert_exists
- name: Start services after cert has been generated.
service:
name: "{{ item }}"
state: started
when: not letsencrypt_cert.stat.exists
when: not cert_exists
with_items: "{{ certbot_create_standalone_stop_services }}"