Matrix Docker Ansible eploy
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

129 wiersze
5.8 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. ansible.builtin.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. - "/etc/cron.d/matrix-ssl-lets-encrypt"
  13. #
  14. # Tasks related to setting up Let's Encrypt's management of certificates
  15. #
  16. - block:
  17. - ansible.builtin.set_fact:
  18. matrix_ssl_lets_encrypt_certbot_docker_image: "{{ matrix_ssl_lets_encrypt_certbot_custom_docker_image if matrix_ssl_lets_encrypt_certbot_challenge_image == 'custom' else matrix_ssl_lets_encrypt_certbot_dns_docker_image if matrix_ssl_lets_encrypt_certbot_challenge_image == 'dns' else matrix_ssl_lets_encrypt_certbot_http_docker_image }}"
  19. - ansible.builtin.set_fact:
  20. matrix_ssl_lets_encrypt_certbot_docker_image_force_pull: "{{ matrix_ssl_lets_encrypt_certbot_docker_image.endswith(':latest') }}"
  21. - ansible.builtin.debug:
  22. msg: "Using certbot docker image: {{ matrix_ssl_lets_encrypt_certbot_docker_image }}"
  23. - name: Ensure certbot Docker image is pulled
  24. docker_image:
  25. name: "{{ matrix_ssl_lets_encrypt_certbot_docker_image }}"
  26. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  27. force_source: "{{ matrix_ssl_lets_encrypt_certbot_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  28. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_ssl_lets_encrypt_certbot_docker_image_force_pull }}"
  29. - name: Ensure cerbot DNS configurations removed
  30. ansible.builtin.file:
  31. path: "{{ matrix_ssl_dns_config_dir_path }}"
  32. state: absent
  33. when: "(matrix_ssl_lets_encrypt_dns_config is not defined) or (matrix_ssl_lets_encrypt_dns_config | length == 0)"
  34. - block:
  35. - name: Ensure cerbot DNS configurations paths exists
  36. ansible.builtin.file:
  37. path: "{{ matrix_ssl_dns_config_dir_path }}"
  38. state: directory
  39. mode: 0770
  40. owner: "{{ matrix_user_username }}"
  41. group: "{{ matrix_user_groupname }}"
  42. recurse: true
  43. - name: List existing cerbot DNS configurations
  44. ansible.builtin.shell: "ls -1 {{ matrix_ssl_dns_config_dir_path }}"
  45. register: dns_config_files
  46. changed_when: false
  47. - name: Remove useless cerbot DNS configurations
  48. ansible.builtin.file:
  49. path: "{{ matrix_ssl_dns_config_dir_path }}/{{ item }}"
  50. state: absent
  51. with_items: "{{ dns_config_files.stdout_lines }}"
  52. when: "item not in matrix_ssl_lets_encrypt_dns_config | map(attribute='name') | list"
  53. - name: Set up certbot DNS provider configurations
  54. ansible.builtin.template:
  55. src: "{{ role_path }}/templates/dns-config/{{ dns_config.template }}.j2"
  56. dest: "{{ matrix_ssl_dns_config_dir_path }}/{{ dns_config.name }}"
  57. mode: 0600
  58. owner: "{{ matrix_user_username }}"
  59. group: "{{ matrix_user_groupname }}"
  60. no_log: true
  61. with_items: "{{ matrix_ssl_lets_encrypt_dns_config }}"
  62. loop_control:
  63. loop_var: dns_config
  64. - name: Ensure awsconfig setup script exists
  65. ansible.builtin.template:
  66. src: "{{ role_path }}/templates/certbot-hook/setup-awsconfig.sh.j2"
  67. dest: "{{ matrix_ssl_dns_config_dir_path }}/setup-awsconfig.sh"
  68. mode: 0700
  69. owner: "{{ matrix_user_username }}"
  70. group: "{{ matrix_user_groupname }}"
  71. with_items: "{{ dns_config_files.stdout_lines }}"
  72. when: "(matrix_ssl_lets_encrypt_dns_config is defined) and (matrix_ssl_lets_encrypt_dns_config | length > 0)"
  73. - name: Obtain Let's Encrypt certificates
  74. ansible.builtin.include_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_lets_encrypt_obtain_for_domain.yml"
  75. with_items: "{{ matrix_ssl_domains_to_obtain_certificates_for }}"
  76. loop_control:
  77. loop_var: domain_name
  78. - name: Ensure Let's Encrypt SSL renewal script installed
  79. ansible.builtin.template:
  80. src: "{{ role_path }}/templates/usr-local-bin/matrix-ssl-lets-encrypt-certificates-renew.j2"
  81. dest: "{{ matrix_local_bin_path }}/matrix-ssl-lets-encrypt-certificates-renew"
  82. mode: 0755
  83. - name: Ensure SSL renewal systemd units installed
  84. ansible.builtin.template:
  85. src: "{{ role_path }}/templates/systemd/{{ item.name }}.j2"
  86. dest: "{{ matrix_systemd_path }}/{{ item.name }}"
  87. mode: 0644
  88. when: "item.applicable | bool"
  89. with_items: "{{ matrix_ssl_renewal_systemd_units_list }}"
  90. when: "matrix_ssl_retrieval_method == 'lets-encrypt'"
  91. #
  92. # Tasks related to getting rid of Let's Encrypt's management of certificates
  93. #
  94. - block:
  95. - name: Ensure matrix-ssl-lets-encrypt-renew cronjob removed
  96. ansible.builtin.file:
  97. path: "{{ matrix_systemd_path }}/{{ item.name }}"
  98. state: absent
  99. when: "not item.applicable | bool"
  100. with_items: "{{ matrix_ssl_renewal_systemd_units_list }}"
  101. - name: Ensure Let's Encrypt SSL renewal script removed
  102. ansible.builtin.file:
  103. path: "{{ matrix_local_bin_path }}/matrix-ssl-lets-encrypt-certificates-renew"
  104. state: absent
  105. - name: Ensure Let's Encrypt DNS provider configurations removed
  106. ansible.builtin.file:
  107. path: "{{ matrix_ssl_dns_config_dir_path }}"
  108. state: absent
  109. when: "matrix_ssl_retrieval_method != 'lets-encrypt'"