Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

138 rivejä
5.4 KiB

  1. ---
  2. # This is a cleanup/migration task, because of to the new way we manage cronjobs (`cron` module) and the new script name.
  3. # This migration task can be removed some time in the future.
  4. - name: (Migration) Remove deprecated Let's Encrypt SSL certificate management files
  5. file:
  6. path: "{{ item }}"
  7. state: absent
  8. with_items:
  9. - "{{ matrix_local_bin_path }}/matrix-ssl-certificates-renew"
  10. - "{{ matrix_cron_path }}/matrix-ssl-certificate-renewal"
  11. - "{{ matrix_cron_path }}/matrix-nginx-proxy-periodic-restarter"
  12. #
  13. # Tasks related to setting up Let's Encrypt's management of certificates
  14. #
  15. - name: (Deprecation) Catch and report renamed settings
  16. fail:
  17. msg: >-
  18. Your configuration contains a variable, which now has a different name.
  19. Please change your configuration to rename the variable (`{{ item.old }}` -> `{{ item.new }}`).
  20. with_items:
  21. - {'old': 'host_specific_matrix_ssl_support_email', 'new': 'matrix_ssl_lets_encrypt_support_email'}
  22. - {'old': 'host_specific_matrix_ssl_lets_encrypt_support_email', 'new': 'matrix_ssl_lets_encrypt_support_email'}
  23. when: "matrix_ssl_retrieval_method == 'lets-encrypt' and item.old in vars"
  24. - name: Fail if required variables are undefined
  25. fail:
  26. msg: "Detected an undefined required variable"
  27. with_items:
  28. - "matrix_ssl_lets_encrypt_support_email"
  29. when: "matrix_ssl_retrieval_method == 'lets-encrypt' and vars[item] is none"
  30. - name: Ensure certbot Docker image is pulled
  31. docker_image:
  32. name: "{{ matrix_ssl_lets_encrypt_certbot_docker_image }}"
  33. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  34. force_source: "{{ matrix_ssl_lets_encrypt_certbot_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  35. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_ssl_lets_encrypt_certbot_docker_image_force_pull }}"
  36. when: "matrix_ssl_retrieval_method == 'lets-encrypt' and not matrix_ssl_lets_encrypt_self_build"
  37. - name: Ensure certbot repository is present on self-build
  38. git:
  39. repo: https://github.com/certbot-docker/certbot-docker/
  40. dest: "{{ matrix_ssl_lets_encrypt_docker_src_files_path }}"
  41. version: "{{ matrix_ssl_lets_encrypt_docker_image.split(':')[1] }}"
  42. force: "yes"
  43. when: "matrix_ssl_lets_encrypt_enabled|bool and matrix_ssl_lets_encrypt_container_image_self_build"
  44. - name: Ensure certbot Docker image is built
  45. docker_image:
  46. name: "{{ matrix_ssl_lets_encrypt_docker_image }}"
  47. source: build
  48. build:
  49. args: "TARGET_ARCH={{ ansible_architecture }}, CERTBOT_VERSION={{ matrix_ssl_lets_encrypt_docker_image.split('v')[1] }}"
  50. dockerfile: "core/Dockerfile"
  51. path: "{{ matrix_ssl_lets_encrypt_docker_src_files_path }}"
  52. pull: yes
  53. when: "matrix_ssl_lets_encrypt_enabled|bool and matrix_ssl_lets_encrypt_container_image_self_build"
  54. - name: Obtain Let's Encrypt certificates
  55. include_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_lets_encrypt_obtain_for_domain.yml"
  56. with_items: "{{ matrix_ssl_domains_to_obtain_certificates_for }}"
  57. loop_control:
  58. loop_var: domain_name
  59. when: "matrix_ssl_retrieval_method == 'lets-encrypt'"
  60. - name: Ensure Let's Encrypt SSL renewal script installed
  61. template:
  62. src: "{{ role_path }}/templates/usr-local-bin/matrix-ssl-lets-encrypt-certificates-renew.j2"
  63. dest: "{{ matrix_local_bin_path }}/matrix-ssl-lets-encrypt-certificates-renew"
  64. mode: 0750
  65. when: "matrix_ssl_retrieval_method == 'lets-encrypt'"
  66. - block:
  67. - name: Ensure periodic SSL renewal cronjob configured (MAILTO)
  68. cron:
  69. user: root
  70. cron_file: matrix-ssl-lets-encrypt
  71. env: yes
  72. name: MAILTO
  73. value: "{{ matrix_ssl_lets_encrypt_support_email }}"
  74. - name: Ensure periodic SSL renewal cronjob configured (matrix-ssl-lets-encrypt-certificates-renew)
  75. cron:
  76. user: root
  77. cron_file: matrix-ssl-lets-encrypt
  78. name: matrix-ssl-lets-encrypt-certificates-renew
  79. state: present
  80. hour: "4"
  81. minute: "15"
  82. day: "*"
  83. job: "{{ matrix_local_bin_path }}/matrix-ssl-lets-encrypt-certificates-renew"
  84. - name: Ensure periodic reloading of matrix-nginx-proxy is configured for SSL renewal (matrix-nginx-proxy-reload)
  85. cron:
  86. user: root
  87. cron_file: matrix-ssl-lets-encrypt
  88. name: matrix-nginx-proxy-reload
  89. state: present
  90. hour: "5"
  91. minute: "20"
  92. day: "*"
  93. job: /bin/systemctl reload matrix-nginx-proxy.service
  94. when: matrix_nginx_proxy_enabled|bool
  95. when: "matrix_ssl_retrieval_method == 'lets-encrypt'"
  96. #
  97. # Tasks related to getting rid of Let's Encrypt's management of certificates
  98. #
  99. # When nginx-proxy is disabled, make sure its reloading cronjob is gone.
  100. # Other cronjobs can potentially remain there (see below).
  101. - name: Ensure matrix-nginx-proxy-reload cronjob removed
  102. cron:
  103. user: root
  104. cron_file: matrix-ssl-lets-encrypt
  105. name: matrix-nginx-proxy-reload
  106. state: absent
  107. when: "not matrix_nginx_proxy_enabled|bool"
  108. - name: Ensure matrix-ssl-lets-encrypt-renew cronjob removed
  109. cron:
  110. user: root
  111. cron_file: matrix-ssl-lets-encrypt
  112. name: matrix-ssl-lets-encrypt-certificates-renew
  113. state: absent
  114. when: "matrix_ssl_retrieval_method != 'lets-encrypt'"
  115. - name: Ensure Let's Encrypt SSL renewal script removed
  116. file:
  117. path: "{{ matrix_local_bin_path }}/matrix-ssl-lets-encrypt-certificates-renew"
  118. state: absent
  119. when: "matrix_ssl_retrieval_method != 'lets-encrypt'"