Skip to content

Commit e01943c

Browse files
authored
Merge pull request #31 from coopdevs/fix/force-renew-only-if-is-needed
Force the renewal only if is needed
2 parents d7b830e + bb00c45 commit e01943c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Create a custom role including the `certbot_nginx` role that generates the certi
7979
Updating Existing Certificates
8080
-------------------------------
8181

82-
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.
82+
If the details for your site have changed since the certificate was created, you can update the domains list and the role checks the difference between the domains presents in the certificate and the list of domains provided and choose if need to renew the certificate or not. If you want to force the renewal process, you can do it by defining `certbot_force_update: true` or passing `--extra-vars "certbot_force_update=true"` via the commandline.
8383

8484

8585
Let's Encrypt Staging Environment

tasks/certificate.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@
1414
{% if letsencrypt_staging %} --staging {% endif %}
1515
when: not letsencrypt_cert.stat.exists
1616

17+
# Check if we need or don't need to force the generation of a new certificate
18+
- name: Extract current domains list from the certificate
19+
shell: >
20+
sudo certbot certificates | grep 'Domains:' | sed 's/\s*Domains: //'
21+
register: old_domains_raw
22+
when: certbot_force_update is not defined
23+
24+
- name: Extract domains list
25+
set_fact:
26+
old_domains: "{{ old_domains_raw['stdout'].split(' ') | sort }}"
27+
when: certbot_force_update is not defined
28+
29+
- name: Compare domains with domains in certificate
30+
set_fact:
31+
certbot_force_update: "{{ old_domains | symmetric_difference(domains) | length | bool }}"
32+
when: certbot_force_update is not defined
33+
1734
- name: Force generation of a new certificate
1835
shell: >
1936
certbot certonly --force-renewal --nginx --email '{{ letsencrypt_email }}'

0 commit comments

Comments
 (0)