Skip to content

Commit 7658299

Browse files
committed
allow certificates to be expanded
1 parent b3a886e commit 7658299

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ certbot_certs: []
1818
# - domains:
1919
# - example3.com
2020
certbot_create_command: >-
21-
{{ certbot_script }} certonly --standalone --noninteractive --agree-tos
21+
{{ certbot_script }} certonly --standalone --noninteractive --expand --agree-tos
2222
--email {{ cert_item.email | default(certbot_admin_email) }}
2323
-d {{ cert_item.domains | join(',') }}
2424

tasks/create-cert-standalone.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
---
2-
- name: Check if certificate already exists.
3-
stat:
4-
path: /etc/letsencrypt/live/{{ cert_item.domains | first | replace('*.', '') }}/cert.pem
5-
register: letsencrypt_cert
2+
- name: Get installed certs.
3+
shell: '{{ certbot_script }} certificates | grep "Domains:" | awk ''{ gsub(/ Domains: /,""); print }'''
4+
changed_when: false
5+
register: letsencrypt_certs
6+
7+
- name: Set cert_exists to false (to check if cert exists).
8+
set_fact:
9+
cert_exists: false
10+
11+
- name: Check if the cert exists.
12+
set_fact:
13+
cert_exists: true
14+
when: cert_item.domains | sort | difference(item) == []
15+
with_list: "{{ letsencrypt_certs.stdout_lines }}"
616

717
- name: Stop services to allow certbot to generate a cert.
818
service:
919
name: "{{ item }}"
1020
state: stopped
11-
when: not letsencrypt_cert.stat.exists
21+
when: cert_exists | default(false) | bool == false
1222
with_items: "{{ certbot_create_standalone_stop_services }}"
1323

1424
- name: Generate new certificate if one doesn't exist.
1525
command: "{{ certbot_create_command }}"
16-
when: not letsencrypt_cert.stat.exists
26+
when: cert_exists | default(false) | bool == false
1727

1828
- name: Start services after cert has been generated.
1929
service:
2030
name: "{{ item }}"
2131
state: started
22-
when: not letsencrypt_cert.stat.exists
32+
when: cert_exists | default(false) | bool == false
2333
with_items: "{{ certbot_create_standalone_stop_services }}"

0 commit comments

Comments
 (0)