Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

141 строка
6.6 KiB

  1. # SPDX-FileCopyrightText: 2024 Slavi Pantaleev
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. - name: Ensure Matrix Authentication Service paths exist
  6. ansible.builtin.file:
  7. path: "{{ item.path }}"
  8. state: directory
  9. mode: '0750'
  10. owner: "{{ matrix_user_name }}"
  11. group: "{{ matrix_group_name }}"
  12. with_items:
  13. - {path: "{{ matrix_authentication_service_base_path }}", when: true}
  14. - {path: "{{ matrix_authentication_service_bin_path }}", when: true}
  15. - {path: "{{ matrix_authentication_service_config_path }}", when: true}
  16. - {path: "{{ matrix_authentication_service_data_path }}", when: true}
  17. - {path: "{{ matrix_authentication_service_data_keys_path }}", when: true}
  18. - {path: "{{ matrix_authentication_service_container_src_files_path }}", when: "{{ matrix_authentication_service_container_image_self_build }}"}
  19. when: "item.when | bool"
  20. - when: matrix_authentication_service_key_management_enabled | bool
  21. block:
  22. - name: Ensure openssl installed
  23. ansible.builtin.package:
  24. name: openssl
  25. state: present
  26. - name: Prepare private key
  27. ansible.builtin.include_tasks: "{{ role_path }}/tasks/util/prepare_key.yml"
  28. with_items: "{{ matrix_authentication_service_key_management_list }}"
  29. loop_control:
  30. loop_var: private_key_definition
  31. # We intentionally do a single fixup pass here (instead of in `prepare_key.yml`)
  32. # so that we reconcile both newly generated keys and any pre-existing keys with
  33. # incorrect ownership/mode in one place.
  34. #
  35. # This primarily protects against setups where `become_user` is effectively not
  36. # honored (for example due to inventory misconfiguration such as `ansible_become=false`),
  37. # which can lead to host-side key generation creating root-owned files.
  38. #
  39. # See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/5033
  40. - name: Ensure Matrix Authentication Service private keys have correct ownership and mode
  41. ansible.builtin.file:
  42. path: "{{ matrix_authentication_service_data_keys_path }}/{{ item.key_file }}"
  43. state: file
  44. mode: '0600'
  45. owner: "{{ matrix_user_name }}"
  46. group: "{{ matrix_group_name }}"
  47. with_items: "{{ matrix_authentication_service_key_management_list }}"
  48. register: matrix_authentication_service_private_keys_result
  49. - name: Ensure Matrix Authentication Service configuration installed
  50. ansible.builtin.copy:
  51. content: "{{ matrix_authentication_service_configuration | to_nice_yaml(indent=2, width=999999) }}"
  52. dest: "{{ matrix_authentication_service_config_path }}/config.yaml"
  53. mode: '0644'
  54. owner: "{{ matrix_user_name }}"
  55. group: "{{ matrix_group_name }}"
  56. register: matrix_authentication_service_config_result
  57. - name: Ensure Matrix Authentication Service support files created
  58. ansible.builtin.template:
  59. src: "{{ item.src }}"
  60. dest: "{{ item.dest }}"
  61. mode: "{{ item.mode }}"
  62. owner: "{{ matrix_user_name }}"
  63. group: "{{ matrix_group_name }}"
  64. with_items:
  65. - src: "{{ role_path }}/templates/env.j2"
  66. dest: "{{ matrix_authentication_service_config_path }}/env"
  67. mode: '0644'
  68. - src: "{{ role_path }}/templates/labels.j2"
  69. dest: "{{ matrix_authentication_service_config_path }}/labels"
  70. mode: '0644'
  71. - src: "{{ role_path }}/templates/bin/register-user.j2"
  72. dest: "{{ matrix_authentication_service_bin_path }}/register-user"
  73. mode: '0755'
  74. - src: "{{ role_path }}/templates/bin/mas-cli.j2"
  75. dest: "{{ matrix_authentication_service_bin_path }}/mas-cli"
  76. mode: '0755'
  77. register: matrix_authentication_service_support_files_result
  78. - name: Ensure Matrix Authentication Service container image is pulled
  79. community.docker.docker_image:
  80. name: "{{ matrix_authentication_service_container_image }}"
  81. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  82. force_source: "{{ matrix_authentication_service_container_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  83. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_authentication_service_container_image_force_pull }}"
  84. when: "not matrix_authentication_service_container_image_self_build | bool"
  85. register: matrix_authentication_service_container_image_pull_result
  86. retries: "{{ devture_playbook_help_container_retries_count }}"
  87. delay: "{{ devture_playbook_help_container_retries_delay }}"
  88. until: matrix_authentication_service_container_image_pull_result is not failed
  89. - when: "matrix_authentication_service_container_image_self_build | bool"
  90. block:
  91. - name: Ensure Matrix Authentication Service repository is present on self-build
  92. ansible.builtin.git:
  93. repo: "{{ matrix_authentication_service_container_repo }}"
  94. version: "{{ matrix_authentication_service_container_repo_version }}"
  95. dest: "{{ matrix_authentication_service_container_src_files_path }}"
  96. force: "yes"
  97. become: true
  98. become_user: "{{ matrix_user_name }}"
  99. - name: Ensure Matrix Authentication Service container image is built
  100. ansible.builtin.command:
  101. cmd: |-
  102. {{ devture_systemd_docker_base_host_command_docker }} buildx build
  103. --tag={{ matrix_authentication_service_container_image }}
  104. --file={{ matrix_authentication_service_container_src_files_path }}/Dockerfile
  105. {{ matrix_authentication_service_container_src_files_path }}
  106. changed_when: true
  107. - name: Ensure Matrix Authentication Service container network is created
  108. community.general.docker_network:
  109. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  110. name: "{{ matrix_authentication_service_container_network }}"
  111. driver: bridge
  112. - name: Ensure matrix-authentication-service.service installed
  113. ansible.builtin.template:
  114. src: "{{ role_path }}/templates/systemd/matrix-authentication-service.service.j2"
  115. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-authentication-service.service"
  116. mode: '0644'
  117. register: matrix_authentication_service_systemd_service_result
  118. - name: Determine whether Matrix Authentication Service needs a restart
  119. ansible.builtin.set_fact:
  120. matrix_authentication_service_restart_necessary: >-
  121. {{
  122. matrix_authentication_service_config_result.changed | default(false)
  123. or matrix_authentication_service_support_files_result.changed | default(false)
  124. or matrix_authentication_service_systemd_service_result.changed | default(false)
  125. or matrix_authentication_service_container_image_pull_result.changed | default(false)
  126. or matrix_authentication_service_private_keys_result.changed | default(false)
  127. }}