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.
 
 

108 lines
4.7 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. - name: Ensure Matrix Authentication Service support files created
  39. ansible.builtin.template:
  40. src: "{{ item.src }}"
  41. dest: "{{ item.dest }}"
  42. mode: "{{ item.mode }}"
  43. owner: "{{ matrix_user_name }}"
  44. group: "{{ matrix_group_name }}"
  45. with_items:
  46. - src: "{{ role_path }}/templates/env.j2"
  47. dest: "{{ matrix_authentication_service_config_path }}/env"
  48. mode: '0644'
  49. - src: "{{ role_path }}/templates/labels.j2"
  50. dest: "{{ matrix_authentication_service_config_path }}/labels"
  51. mode: '0644'
  52. - src: "{{ role_path }}/templates/bin/register-user.j2"
  53. dest: "{{ matrix_authentication_service_bin_path }}/register-user"
  54. mode: '0755'
  55. - src: "{{ role_path }}/templates/bin/mas-cli.j2"
  56. dest: "{{ matrix_authentication_service_bin_path }}/mas-cli"
  57. mode: '0755'
  58. - name: Ensure Matrix Authentication Service container image is pulled
  59. community.docker.docker_image:
  60. name: "{{ matrix_authentication_service_container_image }}"
  61. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  62. force_source: "{{ matrix_authentication_service_container_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  63. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_authentication_service_container_image_force_pull }}"
  64. when: "not matrix_authentication_service_container_image_self_build | bool"
  65. register: result
  66. retries: "{{ devture_playbook_help_container_retries_count }}"
  67. delay: "{{ devture_playbook_help_container_retries_delay }}"
  68. until: result is not failed
  69. - when: "matrix_authentication_service_container_image_self_build | bool"
  70. block:
  71. - name: Ensure Matrix Authentication Service repository is present on self-build
  72. ansible.builtin.git:
  73. repo: "{{ matrix_authentication_service_container_repo }}"
  74. version: "{{ matrix_authentication_service_container_repo_version }}"
  75. dest: "{{ matrix_authentication_service_container_src_files_path }}"
  76. force: "yes"
  77. become: true
  78. become_user: "{{ matrix_user_name }}"
  79. - name: Ensure Matrix Authentication Service container image is built
  80. ansible.builtin.command:
  81. cmd: |-
  82. {{ devture_systemd_docker_base_host_command_docker }} buildx build
  83. --tag={{ matrix_authentication_service_container_image }}
  84. --file={{ matrix_authentication_service_container_src_files_path }}/Dockerfile
  85. {{ matrix_authentication_service_container_src_files_path }}
  86. changed_when: true
  87. - name: Ensure Matrix Authentication Service container network is created
  88. community.general.docker_network:
  89. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  90. name: "{{ matrix_authentication_service_container_network }}"
  91. driver: bridge
  92. - name: Ensure matrix-authentication-service.service installed
  93. ansible.builtin.template:
  94. src: "{{ role_path }}/templates/systemd/matrix-authentication-service.service.j2"
  95. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-authentication-service.service"
  96. mode: 0644