Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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(',') }}

Expand Down
25 changes: 18 additions & 7 deletions tasks/create-cert-standalone.yml
Original file line number Diff line number Diff line change
@@ -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 }}"