2018-12-23 09:00:12 +00:00
|
|
|
---
|
|
|
|
|
2019-01-08 10:24:59 +00:00
|
|
|
# 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
|
|
|
|
|
|
|
|
|
2018-12-23 09:00:12 +00:00
|
|
|
#
|
|
|
|
# Tasks related to setting up Let's Encrypt's management of certificates
|
|
|
|
#
|
|
|
|
|
2019-02-28 09:51:09 +00:00
|
|
|
- name: (Deprecation) Catch and report renamed settings
|
2018-12-23 09:00:12 +00:00
|
|
|
fail:
|
2019-02-28 09:51:09 +00:00
|
|
|
msg: >-
|
|
|
|
Your configuration contains a variable, which now has a different name.
|
|
|
|
Please change your configuration to rename the variable (`{{ item.old }}` -> `{{ item.new }}`).
|
|
|
|
with_items:
|
|
|
|
- {'old': 'host_specific_matrix_ssl_support_email', 'new': 'matrix_ssl_lets_encrypt_support_email'}
|
|
|
|
- {'old': 'host_specific_matrix_ssl_lets_encrypt_support_email', 'new': 'matrix_ssl_lets_encrypt_support_email'}
|
|
|
|
when: "matrix_ssl_retrieval_method == 'lets-encrypt' and item.old in vars"
|
|
|
|
|
|
|
|
- name: Fail if required variables are undefined
|
|
|
|
fail:
|
|
|
|
msg: "Detected an undefined required variable"
|
|
|
|
with_items:
|
2019-04-28 08:02:13 +00:00
|
|
|
- "matrix_ssl_lets_encrypt_support_email"
|
|
|
|
when: "matrix_ssl_retrieval_method == 'lets-encrypt' and vars[item] is none"
|
2018-12-23 09:00:12 +00:00
|
|
|
|
|
|
|
- name: Ensure certbot Docker image is pulled
|
|
|
|
docker_image:
|
|
|
|
name: "{{ matrix_ssl_lets_encrypt_certbot_docker_image }}"
|
2019-05-21 15:29:12 +00:00
|
|
|
source: "pull"
|
2018-12-23 09:00:12 +00:00
|
|
|
when: "matrix_ssl_retrieval_method == 'lets-encrypt'"
|
|
|
|
|
2018-12-24 07:39:27 +00:00
|
|
|
- name: Obtain Let's Encrypt certificates
|
2019-01-12 15:53:00 +00:00
|
|
|
include_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_lets_encrypt_obtain_for_domain.yml"
|
2019-01-16 16:05:48 +00:00
|
|
|
with_items: "{{ matrix_ssl_domains_to_obtain_certificates_for }}"
|
2018-12-23 09:00:12 +00:00
|
|
|
loop_control:
|
|
|
|
loop_var: domain_name
|
|
|
|
when: "matrix_ssl_retrieval_method == 'lets-encrypt'"
|
|
|
|
|
2019-01-08 10:24:59 +00:00
|
|
|
- name: Ensure Let's Encrypt SSL renewal script installed
|
2018-12-23 09:00:12 +00:00
|
|
|
template:
|
2019-01-08 10:24:59 +00:00
|
|
|
src: "{{ role_path }}/templates/usr-local-bin/matrix-ssl-lets-encrypt-certificates-renew.j2"
|
|
|
|
dest: /usr/local/bin/matrix-ssl-lets-encrypt-certificates-renew
|
2018-12-23 09:00:12 +00:00
|
|
|
mode: 0750
|
|
|
|
when: "matrix_ssl_retrieval_method == 'lets-encrypt'"
|
|
|
|
|
2019-01-08 10:24:59 +00:00
|
|
|
- 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
|
2019-05-21 15:37:05 +00:00
|
|
|
hour: "4"
|
|
|
|
minute: "15"
|
2019-04-23 14:49:03 +00:00
|
|
|
day: "*"
|
2019-01-08 10:24:59 +00:00
|
|
|
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
|
2019-05-21 15:37:05 +00:00
|
|
|
hour: "5"
|
|
|
|
minute: "20"
|
2019-04-23 14:49:03 +00:00
|
|
|
day: "*"
|
2019-03-16 19:35:11 +00:00
|
|
|
job: /bin/systemctl reload matrix-nginx-proxy.service
|
2019-05-21 15:25:59 +00:00
|
|
|
when: matrix_nginx_proxy_enabled|bool
|
2018-12-23 09:00:12 +00:00
|
|
|
when: "matrix_ssl_retrieval_method == 'lets-encrypt'"
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Tasks related to getting rid of Let's Encrypt's management of certificates
|
|
|
|
#
|
|
|
|
|
2019-01-08 10:24:59 +00:00
|
|
|
# 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
|
2019-05-21 15:25:59 +00:00
|
|
|
when: "not matrix_nginx_proxy_enabled|bool"
|
2019-01-08 10:24:59 +00:00
|
|
|
|
|
|
|
# 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
|
2018-12-23 09:00:12 +00:00
|
|
|
state: absent
|
|
|
|
when: "matrix_ssl_retrieval_method != 'lets-encrypt'"
|
2019-01-08 10:24:59 +00:00
|
|
|
|
|
|
|
- name: Ensure Let's Encrypt SSL renewal script removed
|
|
|
|
file:
|
|
|
|
path: /usr/local/bin/matrix-ssl-lets-encrypt-certificates-renew
|
|
|
|
state: absent
|
2019-02-28 09:51:09 +00:00
|
|
|
when: "matrix_ssl_retrieval_method != 'lets-encrypt'"
|