Skip to content

Commit 6c4797f

Browse files
authored
Merge pull request #10 from coopdevs/feature/separate-cert-creation-to-task
Move certificate creation to its own task
2 parents 9e85774 + 2058be6 commit 6c4797f

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

tasks/certificate.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
- name: Check if certificate already exists
3+
stat:
4+
path: "/etc/letsencrypt/live/{{ certbot_nginx_cert_name | default(domain_name, true) }}/cert.pem"
5+
register: letsencrypt_cert
6+
7+
- name: Generate new certificate if one doesn't exist
8+
shell: "certbot certonly --nginx --email '{{ letsencrypt_email }}' --agree-tos -d '{{ domain_name }}' {% if certbot_nginx_cert_name is defined %} --cert-name '{{ certbot_nginx_cert_name }}' {% endif %} {% if letsencrypt_staging %} --staging {% endif %}"
9+
when: not letsencrypt_cert.stat.exists

tasks/main.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,5 @@
1414
name: "python-certbot-nginx=0.28.0-1+ubuntu{{ ansible_distribution_version }}.1+certbot+3"
1515
state: present
1616

17-
- name: Check if certificate already exists
18-
stat:
19-
path: "/etc/letsencrypt/live/{{ certbot_nginx_cert_name | default(domain_name, true) }}/cert.pem"
20-
register: letsencrypt_cert
21-
22-
- name: Generate new certificate if one doesn't exist
23-
shell: "certbot certonly --nginx --email '{{ letsencrypt_email }}' --agree-tos -d '{{ domain_name }}' {% if certbot_nginx_cert_name %} --cert-name '{{ certbot_nginx_cert_name }}' {% endif %} {% if letsencrypt_staging %} --staging {% endif %}"
24-
when: not letsencrypt_cert.stat.exists
17+
- import_tasks: certificate.yml
18+
when: domain_name is defined

0 commit comments

Comments
 (0)