Switch to managing cronjobs with the Ansible cron module
As suggested in #65 (Github issue), this patch switches cronjob management from using templates to using Ansible's `cron` module. It also moves the management of the nginx-reload cronjob to `setup_ssl_lets_encrypt.yml`, which is a more fitting place for it (given that this cronjob is only required when Let's Encrypt is used). Pros: - using a module is more Ansible-ish than templating our own files in special directories - more reliable: will fail early (during playbook execution) if `/usr/bin/crontab` is not available, which is more of a guarantee that cron is working fine (idea: we should probably install some cron package using the playbook) Cons: - invocation schedule is no longer configurable, unless we define individual variables for everything or do something smart (splitting on ' ', etc.). Likely not necessary, however. - requires us to deprecate and clean-up after the old way of managing cronjobs, because it's not compatible (using the same file as before means appending additional jobs to it)
This commit is contained in:
@ -1,5 +1,17 @@
|
||||
---
|
||||
|
||||
# This is a cleanup/migration task, because of to the new way we manage cronjobs (`cron` module) and the new script name.
|
||||
# This migration task can be removed some time in the future.
|
||||
- name: (Migration) Remove deprecated Let's Encrypt SSL certificate management files
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
with_items:
|
||||
- /usr/local/bin/matrix-ssl-certificates-renew
|
||||
- /etc/cron.d/matrix-ssl-certificate-renewal
|
||||
- /etc/cron.d/matrix-nginx-proxy-periodic-restarter
|
||||
|
||||
|
||||
#
|
||||
# Tasks related to setting up Let's Encrypt's management of certificates
|
||||
#
|
||||
@ -32,18 +44,44 @@
|
||||
loop_var: domain_name
|
||||
when: "matrix_ssl_retrieval_method == 'lets-encrypt'"
|
||||
|
||||
- name: Ensure SSL renewal script installed
|
||||
- name: Ensure Let's Encrypt SSL renewal script installed
|
||||
template:
|
||||
src: "{{ role_path }}/templates/usr-local-bin/matrix-ssl-certificates-renew.j2"
|
||||
dest: "/usr/local/bin/matrix-ssl-certificates-renew"
|
||||
src: "{{ role_path }}/templates/usr-local-bin/matrix-ssl-lets-encrypt-certificates-renew.j2"
|
||||
dest: /usr/local/bin/matrix-ssl-lets-encrypt-certificates-renew
|
||||
mode: 0750
|
||||
when: "matrix_ssl_retrieval_method == 'lets-encrypt'"
|
||||
|
||||
- name: Ensure periodic SSL renewal cronjob configured
|
||||
template:
|
||||
src: "{{ role_path }}/templates/cron.d/matrix-ssl-certificate-renewal.j2"
|
||||
dest: "/etc/cron.d/matrix-ssl-certificate-renewal"
|
||||
mode: 0600
|
||||
- block:
|
||||
- name: Ensure periodic SSL renewal cronjob configured (MAILTO)
|
||||
cron:
|
||||
user: root
|
||||
cron_file: matrix-ssl-lets-encrypt
|
||||
env: yes
|
||||
name: MAILTO
|
||||
value: "{{ matrix_ssl_lets_encrypt_support_email }}"
|
||||
|
||||
- name: Ensure periodic SSL renewal cronjob configured (matrix-ssl-lets-encrypt-certificates-renew)
|
||||
cron:
|
||||
user: root
|
||||
cron_file: matrix-ssl-lets-encrypt
|
||||
name: matrix-ssl-lets-encrypt-certificates-renew
|
||||
state: present
|
||||
hour: 4
|
||||
minute: 15
|
||||
day: "*/5"
|
||||
job: /usr/local/bin/matrix-ssl-lets-encrypt-certificates-renew
|
||||
|
||||
- name: Ensure periodic reloading of matrix-nginx-proxy is configured for SSL renewal (matrix-nginx-proxy-reload)
|
||||
cron:
|
||||
user: root
|
||||
cron_file: matrix-ssl-lets-encrypt
|
||||
name: matrix-nginx-proxy-reload
|
||||
state: present
|
||||
hour: 4
|
||||
minute: 20
|
||||
day: "*/5"
|
||||
job: /usr/bin/systemctl reload matrix-nginx-proxy.service
|
||||
when: matrix_nginx_proxy_enabled
|
||||
when: "matrix_ssl_retrieval_method == 'lets-encrypt'"
|
||||
|
||||
|
||||
@ -51,11 +89,26 @@
|
||||
# Tasks related to getting rid of Let's Encrypt's management of certificates
|
||||
#
|
||||
|
||||
- name: Ensure Let's Encrypt SSL certificate management files removed
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
# When nginx-proxy is disabled, make sure its reloading cronjob is gone.
|
||||
# Other cronjobs can potentially remain there (see below).
|
||||
- name: Ensure matrix-nginx-proxy-reload cronjob removed
|
||||
cron:
|
||||
user: root
|
||||
cron_file: matrix-ssl-lets-encrypt
|
||||
name: matrix-nginx-proxy-reload
|
||||
state: absent
|
||||
when: "not matrix_nginx_proxy_enabled"
|
||||
|
||||
# When Let's Encrypt is not used at all, remove all cronjobs in that cron file.
|
||||
- name: Ensure matrix-ssl-lets-encrypt-renew cronjob removed
|
||||
cron:
|
||||
user: root
|
||||
cron_file: matrix-ssl-lets-encrypt
|
||||
state: absent
|
||||
with_items:
|
||||
- /usr/local/bin/matrix-ssl-certificates-renew
|
||||
- /etc/cron.d/matrix-ssl-certificate-renewal
|
||||
when: "matrix_ssl_retrieval_method != 'lets-encrypt'"
|
||||
|
||||
- name: Ensure Let's Encrypt SSL renewal script removed
|
||||
file:
|
||||
path: /usr/local/bin/matrix-ssl-lets-encrypt-certificates-renew
|
||||
state: absent
|
||||
when: "matrix_ssl_retrieval_method != 'lets-encrypt'"
|
Reference in New Issue
Block a user