Skip to content

Commit 2f24488

Browse files
authored
Merge pull request #7 from coopdevs/make-cert-name-optional
Make cert name optional
2 parents adc1a49 + 6a16c08 commit 2f24488

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ Role Variables
1414
```yaml
1515
domain_name: www.mydomain.io
1616
letsencrypt_email: myaccount@letsencrypt.org
17+
certbot_nginx_cert_name: mycert # optional
1718
```
1819
20+
if set, `certbot_nginx_cert_name`'s value will be passed to the certbot's `--cert-name` argument, which is used to identify the certificate in certbot command such as `certbot delete`. You will see a list of certificates identified with this name by running `certbot certificates`. This name will also be used as the file paths for the certificate in `/etc/letsencrypt/live/`.
21+
1922
Example Playbook
2023
----------------
2124

@@ -25,6 +28,7 @@ Example Playbook
2528
- role: coopdevs.certbot-nginx
2629
domain_name: www.mydomain.io
2730
letsencrypt_email: myaccount@letsencrypt.org
31+
certbot_nginx_cert_name: mycert
2832
```
2933

3034
Let's Encrypt Staging Environment

tasks/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66

77
- name: Install certbot
88
package:
9-
name: letsencrypt
9+
name: "certbot=0.26.1-1+ubuntu{{ ansible_distribution_version }}.1+certbot+2"
1010
state: present
1111

1212
- name: Install certbot-nginx plugin
1313
package:
14-
name: python-certbot-nginx
14+
name: "python-certbot-nginx=0.25.0-2+ubuntu{{ ansible_distribution_version }}.1+certbot+1"
1515
state: present
1616

1717
- name: Check if certificate already exists
1818
stat:
19-
path: "/etc/letsencrypt/live/{{ domain_name }}/cert.pem"
19+
path: "/etc/letsencrypt/live/{{ certbot_nginx_cert_name | default(domain_name, true) }}/cert.pem"
2020
register: letsencrypt_cert
2121

2222
- name: Generate new certificate if one doesn't exist
23-
shell: "certbot certonly --nginx --cert-name {{ cert_name }} --email {{ letsencrypt_email }} --agree-tos -d {{ domain_name }} {% if letsencrypt_staging %} --staging {% endif %}"
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 %}"
2424
when: not letsencrypt_cert.stat.exists

0 commit comments

Comments
 (0)