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: # - domains:
# - example3.com # - example3.com
certbot_create_command: >- 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) }} --email {{ cert_item.email | default(certbot_admin_email) }}
-d {{ cert_item.domains | join(',') }} -d {{ cert_item.domains | join(',') }}

View File

@ -1,23 +1,34 @@
--- ---
- name: Check if certificate already exists. - name: Get installed certs.
stat: shell: |
path: /etc/letsencrypt/live/{{ cert_item.domains | first | replace('*.', '') }}/cert.pem {{ certbot_script }} certificates | grep "Domains:" | awk '{ gsub(/ Domains: /,""); print }'
register: letsencrypt_cert 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. - name: Stop services to allow certbot to generate a cert.
service: service:
name: "{{ item }}" name: "{{ item }}"
state: stopped state: stopped
when: not letsencrypt_cert.stat.exists when: not cert_exists
with_items: "{{ certbot_create_standalone_stop_services }}" with_items: "{{ certbot_create_standalone_stop_services }}"
- name: Generate new certificate if one doesn't exist. - name: Generate new certificate if one doesn't exist.
command: "{{ certbot_create_command }}" command: "{{ certbot_create_command }}"
when: not letsencrypt_cert.stat.exists when: not cert_exists
- name: Start services after cert has been generated. - name: Start services after cert has been generated.
service: service:
name: "{{ item }}" name: "{{ item }}"
state: started state: started
when: not letsencrypt_cert.stat.exists when: not cert_exists
with_items: "{{ certbot_create_standalone_stop_services }}" with_items: "{{ certbot_create_standalone_stop_services }}"