Skip to content

Commit e5c0dc1

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

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-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: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
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: |
4+
{{ certbot_script }} certificates | grep "Domains:" | awk '{ gsub(/ Domains: /,""); print }'
5+
changed_when: false
6+
register: letsencrypt_certs
7+
8+
- name: Set cert_exists to false (to check if cert exists).
9+
set_fact:
10+
cert_exists: false
11+
12+
- name: Check if the cert exists.
13+
set_fact:
14+
cert_exists: true
15+
when: cert_item.domains | sort | difference(item) == []
16+
with_list: "{{ letsencrypt_certs.stdout_lines }}"
617

718
- name: Stop services to allow certbot to generate a cert.
819
service:
920
name: "{{ item }}"
1021
state: stopped
11-
when: not letsencrypt_cert.stat.exists
22+
when: not cert_exists
1223
with_items: "{{ certbot_create_standalone_stop_services }}"
1324

1425
- name: Generate new certificate if one doesn't exist.
1526
command: "{{ certbot_create_command }}"
16-
when: not letsencrypt_cert.stat.exists
27+
when: not cert_exists
1728

1829
- name: Start services after cert has been generated.
1930
service:
2031
name: "{{ item }}"
2132
state: started
22-
when: not letsencrypt_cert.stat.exists
33+
when: not cert_exists
2334
with_items: "{{ certbot_create_standalone_stop_services }}"

0 commit comments

Comments
 (0)