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.
 
 

121 lines
5.5 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. - name: Ensure Matrix Authentication Service configuration installed
  32. ansible.builtin.copy:
  33. content: "{{ matrix_authentication_service_configuration | to_nice_yaml(indent=2, width=999999) }}"
  34. dest: "{{ matrix_authentication_service_config_path }}/config.yaml"
  35. mode: '0644'
  36. owner: "{{ matrix_user_name }}"
  37. group: "{{ matrix_group_name }}"
  38. register: matrix_authentication_service_config_result
  39. - name: Ensure Matrix Authentication Service support files created
  40. ansible.builtin.template:
  41. src: "{{ item.src }}"
  42. dest: "{{ item.dest }}"
  43. mode: "{{ item.mode }}"
  44. owner: "{{ matrix_user_name }}"
  45. group: "{{ matrix_group_name }}"
  46. with_items:
  47. - src: "{{ role_path }}/templates/env.j2"
  48. dest: "{{ matrix_authentication_service_config_path }}/env"
  49. mode: '0644'
  50. - src: "{{ role_path }}/templates/labels.j2"
  51. dest: "{{ matrix_authentication_service_config_path }}/labels"
  52. mode: '0644'
  53. - src: "{{ role_path }}/templates/bin/register-user.j2"
  54. dest: "{{ matrix_authentication_service_bin_path }}/register-user"
  55. mode: '0755'
  56. - src: "{{ role_path }}/templates/bin/mas-cli.j2"
  57. dest: "{{ matrix_authentication_service_bin_path }}/mas-cli"
  58. mode: '0755'
  59. register: matrix_authentication_service_support_files_result
  60. - name: Ensure Matrix Authentication Service container image is pulled
  61. community.docker.docker_image:
  62. name: "{{ matrix_authentication_service_container_image }}"
  63. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  64. force_source: "{{ matrix_authentication_service_container_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  65. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_authentication_service_container_image_force_pull }}"
  66. when: "not matrix_authentication_service_container_image_self_build | bool"
  67. register: matrix_authentication_service_container_image_pull_result
  68. retries: "{{ devture_playbook_help_container_retries_count }}"
  69. delay: "{{ devture_playbook_help_container_retries_delay }}"
  70. until: matrix_authentication_service_container_image_pull_result is not failed
  71. - when: "matrix_authentication_service_container_image_self_build | bool"
  72. block:
  73. - name: Ensure Matrix Authentication Service repository is present on self-build
  74. ansible.builtin.git:
  75. repo: "{{ matrix_authentication_service_container_repo }}"
  76. version: "{{ matrix_authentication_service_container_repo_version }}"
  77. dest: "{{ matrix_authentication_service_container_src_files_path }}"
  78. force: "yes"
  79. become: true
  80. become_user: "{{ matrix_user_name }}"
  81. - name: Ensure Matrix Authentication Service container image is built
  82. ansible.builtin.command:
  83. cmd: |-
  84. {{ devture_systemd_docker_base_host_command_docker }} buildx build
  85. --tag={{ matrix_authentication_service_container_image }}
  86. --file={{ matrix_authentication_service_container_src_files_path }}/Dockerfile
  87. {{ matrix_authentication_service_container_src_files_path }}
  88. changed_when: true
  89. - name: Ensure Matrix Authentication Service container network is created
  90. community.general.docker_network:
  91. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  92. name: "{{ matrix_authentication_service_container_network }}"
  93. driver: bridge
  94. - name: Ensure matrix-authentication-service.service installed
  95. ansible.builtin.template:
  96. src: "{{ role_path }}/templates/systemd/matrix-authentication-service.service.j2"
  97. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-authentication-service.service"
  98. mode: '0644'
  99. register: matrix_authentication_service_systemd_service_result
  100. - name: Determine whether Matrix Authentication Service needs a restart
  101. ansible.builtin.set_fact:
  102. matrix_authentication_service_restart_necessary: >-
  103. {{
  104. matrix_authentication_service_config_result.changed | default(false)
  105. or matrix_authentication_service_support_files_result.changed | default(false)
  106. or matrix_authentication_service_systemd_service_result.changed | default(false)
  107. or matrix_authentication_service_container_image_pull_result.changed | default(false)
  108. }}