Skip to content

Commit

Permalink
feat: add certificate download for temporary environments
Browse files Browse the repository at this point in the history
community.crypto.acme_certificate does use the existing certificate file
to check for the validity in order to decide whether a certificate needs
renewal.

As this file isn't kept if running the playbook on a non persistent
environment such as a containerized ci runner this leads to a
certificate renewal on each playbook execution which might hit the limit
of 5 certs per seven days as configured on letsencrypt depending on the
configured schedule.

By downloading the certificate from the webserver beforehand to the
certificate file this check should work as expected again
  • Loading branch information
Christoph Sieber authored and Christoph Sieber committed Dec 21, 2023
1 parent 722df0f commit 5e7acaa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions roles/acme/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ acme_s3_config_region: eu-west-1
acme_s3_install_prerequisites: true
acme_local_validation_path: /var/www/html
acme_azure_purge_state: absent

### certificate download for non-persistent environments
acme_download_cert: false
13 changes: 13 additions & 0 deletions roles/acme/tasks/download_cert.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Fetch current certificate from https server
ansible.community.crypto.get_certificate:
host: "{{ acme_cert_download_host | default(acme_domain.subject_alt_name[0]) }}"
port: "{{ acme_cert_download_port | default('443') }}"
server_name: "{{ acme_cert_san_name | default(acme_domain.subject_alt_name[0]) }}"
register: certificate

- name: Write fetched certificate to file
ansible.builtin.copy:
content: "{{ certificate.cert }}"
dest: "{{ acme_cert_path }}"
mode: "0644"
5 changes: 5 additions & 0 deletions roles/acme/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
- name: Preconditions
ansible.builtin.include_tasks: preconditions.yml

- name: Download Certificate from https
ansible.builtin.include_tasks: download_cert.yml
when:
- acme_download_cert

- name: Run key generation
ansible.builtin.include_tasks: create-keys.yml

Expand Down

0 comments on commit 5e7acaa

Please sign in to comment.