Auto-purge orphaned Let's Encrypt renewal configuration files

This commit is contained in:
Slavi Pantaleev
2022-10-25 06:28:24 +03:00
parent 69ae35bb23
commit 9c549a185f
3 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,27 @@
---
- name: Check if a Let's Encrypt renewal configuration directory exists
ansible.builtin.stat:
path: "{{ matrix_ssl_config_dir_path }}/renewal"
register: matrix_ssl_config_renewal_directory_stat_result
- when: matrix_ssl_config_renewal_directory_stat_result.stat.exists | bool
block:
- name: Determine current Let's Encrypt renewal configs
ansible.builtin.find:
path: "{{ matrix_ssl_config_dir_path }}/renewal"
patterns: ".*.conf$"
use_regex: true
register: matrix_ssl_current_renewal_config_files
- name: Determine unnecessary Let's Encrypt renewal configs
ansible.builtin.set_fact:
matrix_ssl_current_renewal_config_files_to_purge: "{{ matrix_ssl_current_renewal_config_files_to_purge | default([]) + [item.path] }}"
with_items: "{{ matrix_ssl_current_renewal_config_files.files }}"
when: "item.path | basename | replace('.conf', '') not in matrix_ssl_domains_to_obtain_certificates_for"
- name: Purge unneceessary Let's Encrypt renewal config files
ansible.builtin.file:
path: "{{ item }}"
state: absent
with_items: "{{ matrix_ssl_current_renewal_config_files_to_purge | default([]) }}"

View File

@ -18,6 +18,9 @@
- when: "matrix_ssl_retrieval_method == 'lets-encrypt'"
block:
- when: matrix_ssl_orphaned_renewal_configs_purging_enabled | bool
ansible.builtin.import_tasks: "{{ role_path }}/tasks/ssl/purge_ssl_lets_encrypt_orphaned_configs.yml"
- name: Ensure certbot Docker image is pulled
docker_image:
name: "{{ matrix_ssl_lets_encrypt_certbot_docker_image }}"