Skip to content

Commit 8525161

Browse files
authored
Merge pull request #23 from Matt-Yorkley/update_certs
Allow updating existing certs using --extra-vars "certbot_force_update=true
2 parents a0110db + 57ae914 commit 8525161

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ Create a custom role including the `certbot_nginx` role that generates the certi
6868
loop_var: domain_name
6969
```
7070

71-
> You need to declare the `loop_control` to map the `item` var of the `with_item` loop with the `loop_var` value as `domain_name`. See the [`loop_controll` doc](https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html?highlight=loop_control#loop-control)
71+
> You need to declare the `loop_control` to map the `item` var of the `with_item` loop with the `loop_var` value as `domain_name`. See the [`loop_control` doc](https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html?highlight=loop_control#loop-control)
72+
73+
Updating Existing Certificates
74+
-------------------------------
75+
76+
If the details for your site have changed since the certificate was created, you can update it by defining `certbot_force_update: true` or passing `--extra-vars "certbot_force_update=true"` via the commandline.
77+
7278

7379
Let's Encrypt Staging Environment
7480
---------------------------------

handlers/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: reload nginx
3+
service:
4+
name: nginx
5+
state: reloaded

tasks/certificate.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,23 @@
44
path: "/etc/letsencrypt/live/{{ certbot_nginx_cert_name | default(domain_name, true) }}/cert.pem"
55
register: letsencrypt_cert
66

7-
- name: Generate new certificate if one doesn't exist
7+
- name: "Generate new certificate if one doesn't exist"
88
shell: >
9-
"certbot certonly --nginx --email '{{ letsencrypt_email }}'
9+
certbot certonly --nginx --email '{{ letsencrypt_email }}'
1010
--agree-tos -d '{{ domain_name }}'
1111
{% if certbot_nginx_cert_name is defined %}
1212
--cert-name '{{ certbot_nginx_cert_name }}'
1313
{% endif %}
14-
{% if letsencrypt_staging %} --staging {% endif %}"
14+
{% if letsencrypt_staging %} --staging {% endif %}
1515
when: not letsencrypt_cert.stat.exists
16+
17+
- name: Force generation of a new certificate
18+
shell: >
19+
certbot certonly --force-renewal --nginx --email '{{ letsencrypt_email }}'
20+
--agree-tos -d '{{ domain_name }}'
21+
{% if certbot_nginx_cert_name is defined %}
22+
--cert-name '{{ certbot_nginx_cert_name }}'
23+
{% endif %}
24+
{% if letsencrypt_staging %} --staging {% endif %}
25+
when: letsencrypt_cert.stat.exists and certbot_force_update is defined
26+
notify: reload nginx

0 commit comments

Comments
 (0)