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.
 
 
 

129 lines
5.2 KiB

  1. # SPDX-FileCopyrightText: 2026 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2026 Matěj Cepl
  3. # SPDX-FileCopyrightText: 2026 MDAD project contributors
  4. #
  5. # SPDX-License-Identifier: AGPL-3.0-or-later
  6. ---
  7. - name: Ensure gomuks paths exist
  8. ansible.builtin.file:
  9. path: "{{ item.path }}"
  10. state: directory
  11. mode: '0750'
  12. owner: "{{ matrix_user_name }}"
  13. group: "{{ matrix_group_name }}"
  14. with_items:
  15. - {path: "{{ matrix_client_gomuks_data_path }}", when: true}
  16. - {path: "{{ matrix_client_gomuks_data_path }}/config", when: true}
  17. - {path: "{{ matrix_client_gomuks_data_path }}/logs", when: true}
  18. - {path: "{{ matrix_client_gomuks_data_path }}/data", when: true}
  19. when: "item.when | bool"
  20. - name: Initialize existing gomuks configuration
  21. ansible.builtin.set_fact:
  22. matrix_client_gomuks_existing_config: {}
  23. no_log: true
  24. - name: Check whether the gomuks configuration exists
  25. ansible.builtin.stat:
  26. path: "{{ matrix_client_gomuks_data_path }}/config/config.yaml"
  27. register: matrix_client_gomuks_config_stat
  28. - name: Read the existing gomuks configuration
  29. when: matrix_client_gomuks_config_stat.stat.exists | bool
  30. ansible.builtin.slurp:
  31. src: "{{ matrix_client_gomuks_data_path }}/config/config.yaml"
  32. register: matrix_client_gomuks_config_slurp
  33. no_log: true
  34. - name: Parse the existing gomuks configuration
  35. when: matrix_client_gomuks_config_stat.stat.exists | bool
  36. ansible.builtin.set_fact:
  37. matrix_client_gomuks_existing_config: "{{ matrix_client_gomuks_config_slurp.content | b64decode | from_yaml }}"
  38. no_log: true
  39. - name: Select the gomuks VAPID key pair
  40. vars:
  41. matrix_client_gomuks_existing_push_config: "{{ matrix_client_gomuks_existing_config.get('push') or {} }}"
  42. matrix_client_gomuks_existing_vapid_private_key: "{{ matrix_client_gomuks_existing_push_config.get('vapid_private_key', '') }}"
  43. matrix_client_gomuks_existing_vapid_public_key: "{{ matrix_client_gomuks_existing_push_config.get('vapid_public_key', '') }}"
  44. matrix_client_gomuks_existing_vapid_key_pair_valid: >-
  45. {{
  46. matrix_client_gomuks_existing_vapid_private_key is match('^[A-Za-z0-9_-]{43}$')
  47. and matrix_client_gomuks_existing_vapid_public_key is match('^B[A-Za-z0-9_-]{86}$')
  48. }}
  49. ansible.builtin.set_fact:
  50. matrix_client_gomuks_push_vapid_private_key_actual: >-
  51. {{
  52. matrix_client_gomuks_push_vapid_private_key
  53. if matrix_client_gomuks_push_vapid_private_key
  54. else matrix_client_gomuks_existing_vapid_private_key
  55. if matrix_client_gomuks_existing_vapid_key_pair_valid
  56. else ''
  57. }}
  58. matrix_client_gomuks_push_vapid_public_key_actual: >-
  59. {{
  60. matrix_client_gomuks_push_vapid_public_key
  61. if matrix_client_gomuks_push_vapid_public_key
  62. else matrix_client_gomuks_existing_vapid_public_key
  63. if matrix_client_gomuks_existing_vapid_key_pair_valid
  64. else ''
  65. }}
  66. no_log: true
  67. - name: Ensure gomuks container image is pulled
  68. community.docker.docker_image_pull:
  69. name: "{{ matrix_client_gomuks_container_image }}"
  70. pull: always
  71. register: matrix_client_gomuks_container_image_pull_result
  72. retries: "{{ devture_playbook_help_container_retries_count }}"
  73. delay: "{{ devture_playbook_help_container_retries_delay }}"
  74. until: matrix_client_gomuks_container_image_pull_result is not failed
  75. - name: Ensure gomuks configuration installed
  76. ansible.builtin.template:
  77. src: "{{ role_path }}/templates/config.yaml.j2"
  78. dest: "{{ matrix_client_gomuks_data_path }}/config/config.yaml"
  79. mode: '0640'
  80. owner: "{{ matrix_user_name }}"
  81. group: "{{ matrix_group_name }}"
  82. register: matrix_client_gomuks_config_result
  83. - name: Ensure gomuks support files installed
  84. ansible.builtin.template:
  85. src: "{{ item.src }}"
  86. dest: "{{ matrix_client_gomuks_data_path }}/{{ item.name }}"
  87. mode: "{{ item.mode }}"
  88. owner: "{{ matrix_user_name }}"
  89. group: "{{ matrix_group_name }}"
  90. with_items:
  91. - {src: "{{ role_path }}/templates/labels.j2", name: "labels", mode: "0644"}
  92. - {src: "{{ role_path }}/templates/env.j2", name: "env", mode: "0640"}
  93. register: matrix_client_gomuks_support_files_result
  94. - name: Ensure gomuks container network is created
  95. when: matrix_client_gomuks_container_network != 'host'
  96. community.general.docker_network:
  97. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  98. name: "{{ matrix_client_gomuks_container_network }}"
  99. driver: bridge
  100. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  101. - name: Ensure matrix-client-gomuks.service installed
  102. ansible.builtin.template:
  103. src: "{{ role_path }}/templates/systemd/matrix-client-gomuks.service.j2"
  104. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-client-gomuks.service"
  105. mode: '0644'
  106. register: matrix_client_gomuks_systemd_service_result
  107. - name: Determine whether gomuks needs a restart
  108. ansible.builtin.set_fact:
  109. matrix_client_gomuks_restart_necessary: >-
  110. {{
  111. matrix_client_gomuks_config_result.changed | default(false)
  112. or matrix_client_gomuks_support_files_result.changed | default(false)
  113. or matrix_client_gomuks_systemd_service_result.changed | default(false)
  114. or matrix_client_gomuks_container_image_pull_result.changed | default(false)
  115. }}