Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force the renewal only if is needed #31

Merged
merged 2 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Create a custom role including the `certbot_nginx` role that generates the certi
Updating Existing Certificates
-------------------------------

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.
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.


Let's Encrypt Staging Environment
Expand Down
17 changes: 17 additions & 0 deletions tasks/certificate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@
{% if letsencrypt_staging %} --staging {% endif %}
when: not letsencrypt_cert.stat.exists

# Check if we need or don't need to force the generation of a new certificate
- name: Extract current domains list from the certificate
shell: >
sudo certbot certificates | grep 'Domains:' | sed 's/\s*Domains: //'
register: old_domains_raw
when: certbot_force_update is not defined

- name: Extract domains list
set_fact:
old_domains: "{{ old_domains_raw['stdout'].split(' ') | sort }}"
when: certbot_force_update is not defined

- name: Compare domains with domains in certificate
set_fact:
certbot_force_update: "{{ old_domains | symmetric_difference(domains) | length | bool }}"
when: certbot_force_update is not defined

- name: Force generation of a new certificate
shell: >
certbot certonly --force-renewal --nginx --email '{{ letsencrypt_email }}'
Expand Down