Skip to content

Commit b72337a

Browse files
enricostanodanypr92
authored andcommitted
Move certificate creation to is own task
The idea is to be able to import the task to create certificates from other roles. The current use case is to create multiple certificates.
1 parent 9e85774 commit b72337a

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

tasks/certificate.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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 %} --cert-name '{{ certbot_nginx_cert_name }}' {% endif %} {% if letsencrypt_staging %} --staging {% endif %}"
9+
when: not letsencrypt_cert.stat.exists
10+

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)