Matrix Docker Ansible eploy
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

201 řádky
8.3 KiB

  1. ---
  2. - import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml"
  3. - name: Ensure Appservice IRC paths exist
  4. file:
  5. path: "{{ item.path }}"
  6. state: directory
  7. mode: 0750
  8. owner: "{{ matrix_user_username }}"
  9. group: "{{ matrix_user_groupname }}"
  10. with_items:
  11. - {path: "{{ matrix_appservice_irc_base_path }}", when: true}
  12. - {path: "{{ matrix_appservice_irc_config_path }}", when: true}
  13. - {path: "{{ matrix_appservice_irc_data_path }}", when: true}
  14. - {path: "{{ matrix_appservice_irc_docker_src_files_path }}", when: "{{ matrix_appservice_irc_container_image_self_build }}"}
  15. when: item.when|bool
  16. - name: Check if an old passkey file already exists
  17. stat:
  18. path: "{{ matrix_appservice_irc_base_path }}/passkey.pem"
  19. register: matrix_appservice_irc_stat_passkey
  20. - block:
  21. - name: (Data relocation) Ensure matrix-appservice-irc.service is stopped
  22. service:
  23. name: matrix-appservice-irc
  24. state: stopped
  25. daemon_reload: true
  26. failed_when: false
  27. - name: (Data relocation) Move AppService IRC passkey.pem file to ./data directory
  28. command: "mv {{ matrix_appservice_irc_base_path }}/passkey.pem {{ matrix_appservice_irc_data_path }}/passkey.pem"
  29. - name: (Data relocation) Move AppService IRC database files to ./data directory
  30. command: "mv {{ matrix_appservice_irc_base_path }}/{{ item }} {{ matrix_appservice_irc_data_path }}/{{ item }}"
  31. with_items:
  32. - rooms.db
  33. - users.db
  34. failed_when: false
  35. when: "matrix_appservice_irc_stat_passkey.stat.exists"
  36. - set_fact:
  37. matrix_appservice_irc_requires_restart: false
  38. - block:
  39. - name: Check if a nedb database already exists
  40. stat:
  41. path: "{{ matrix_appservice_irc_data_path }}/users.db"
  42. register: matrix_appservice_irc_nedb_database_path_local_stat_result
  43. - block:
  44. - import_tasks: "{{ role_path }}/tasks/migrate_nedb_to_postgres.yml"
  45. - set_fact:
  46. matrix_appservice_irc_requires_restart: true
  47. when: "matrix_appservice_irc_nedb_database_path_local_stat_result.stat.exists|bool"
  48. when: "matrix_appservice_irc_database_engine == 'postgres'"
  49. - name: Ensure Appservice IRC image is pulled
  50. docker_image:
  51. name: "{{ matrix_appservice_irc_docker_image }}"
  52. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  53. force_source: "{{ matrix_appservice_irc_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  54. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_appservice_irc_docker_image_force_pull }}"
  55. when: "matrix_appservice_irc_enabled|bool and not matrix_appservice_irc_container_image_self_build|bool"
  56. register: result
  57. retries: "{{ matrix_container_retries_count }}"
  58. delay: "{{ matrix_container_retries_delay }}"
  59. until: result is not failed
  60. - name: Ensure matrix-appservice-irc repository is present when self-building
  61. git:
  62. repo: "{{ matrix_appservice_irc_docker_repo }}"
  63. dest: "{{ matrix_appservice_irc_docker_src_files_path }}"
  64. force: "yes"
  65. register: matrix_appservice_irc_git_pull_results
  66. when: "matrix_appservice_irc_enabled|bool and matrix_appservice_irc_container_image_self_build|bool"
  67. - name: Ensure matrix-appservice-irc Docker image is built
  68. docker_image:
  69. name: "{{ matrix_appservice_irc_docker_image }}"
  70. source: build
  71. force_source: "{{ matrix_appservice_irc_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  72. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_appservice_irc_git_pull_results.changed }}"
  73. build:
  74. dockerfile: Dockerfile
  75. path: "{{ matrix_appservice_irc_docker_src_files_path }}"
  76. pull: true
  77. when: "matrix_appservice_irc_enabled|bool and matrix_appservice_irc_container_image_self_build|bool and matrix_appservice_irc_git_pull_results.changed"
  78. - name: Ensure Matrix Appservice IRC config installed
  79. copy:
  80. content: "{{ matrix_appservice_irc_configuration|to_nice_yaml(indent=2, width=999999) }}"
  81. dest: "{{ matrix_appservice_irc_config_path }}/config.yaml"
  82. mode: 0644
  83. owner: "{{ matrix_user_username }}"
  84. group: "{{ matrix_user_groupname }}"
  85. - name: Check if Appservice IRC passkey exists
  86. stat:
  87. path: "{{ matrix_appservice_irc_data_path }}/passkey.pem"
  88. register: irc_passkey_file
  89. - name: Generate Appservice IRC passkey if it doesn't exist
  90. shell: "{{ matrix_host_command_openssl }} genpkey -out {{ matrix_appservice_irc_data_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:2048"
  91. become: true
  92. become_user: "{{ matrix_user_username }}"
  93. when: "not irc_passkey_file.stat.exists"
  94. # In the past, we used to generate the passkey.pem file with root, so permissions may not be okay.
  95. # Fix it.
  96. - name: (Migration) Ensure Appservice IRC passkey permissions are okay
  97. file:
  98. path: "{{ matrix_appservice_irc_data_path }}/passkey.pem"
  99. mode: 0644
  100. owner: "{{ matrix_user_username }}"
  101. group: "{{ matrix_user_groupname }}"
  102. # Ideally, we'd like to generate the final registration.yaml file by ourselves.
  103. #
  104. # However, the IRC bridge supports multiple servers, which leads to multiple
  105. # users/aliases/rooms rules in the registration file.
  106. #
  107. # Generating a proper file by ourselves is complicated and may lead to deviation
  108. # from what the bridge is doing.
  109. #
  110. # Instead, we do another hacky thing - asking the bridge to generate a template,
  111. # and then we parse it and fix it up with our own AS/HS token.
  112. # We need to do this, because:
  113. # - we'd like to have an up-to-date registration file
  114. # - we can achieve this by asking the bridge to rebuild it each time
  115. # - however, the bridge insists on regenerating all tokens each time
  116. # - .. which is not friendly for integrating with the homeserver
  117. #
  118. # So we have a hybrid approach. We ask the bridge to always generate
  119. # an up-to-date file, and we fix it up with some static values later on,
  120. # to produce a final registration.yaml file, as we desire.
  121. - name: Generate Appservice IRC registration-template.yaml
  122. shell: >-
  123. {{ matrix_host_command_docker }} run --rm --name matrix-appservice-irc-gen
  124. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  125. --cap-drop=ALL
  126. -v {{ matrix_appservice_irc_config_path }}:/config:z
  127. -v {{ matrix_appservice_irc_data_path }}:/data:z
  128. --entrypoint=/bin/bash
  129. {{ matrix_appservice_irc_docker_image }}
  130. -c
  131. 'node app.js
  132. -r
  133. -f /config/registration-template.yaml
  134. -u "http://matrix-appservice-irc:9999"
  135. -c /config/config.yaml
  136. -l irc_bot'
  137. changed_when: false
  138. - name: Read Appservice IRC registration-template.yaml
  139. slurp:
  140. src: "{{ matrix_appservice_irc_config_path }}/registration-template.yaml"
  141. register: matrix_appservice_irc_registration_template_slurp
  142. - name: Remove unnecessary Appservice IRC registration-template.yaml
  143. file:
  144. path: "{{ matrix_appservice_irc_config_path }}/registration-template.yaml"
  145. state: absent
  146. changed_when: false
  147. - name: Parse registration-template.yaml
  148. set_fact:
  149. matrix_appservice_irc_registration_template: "{{ matrix_appservice_irc_registration_template_slurp['content'] | b64decode | from_yaml }}"
  150. - name: Combine registration-template.yaml and own registration override config
  151. set_fact:
  152. matrix_appservice_irc_registration: "{{ matrix_appservice_irc_registration_template|combine(matrix_appservice_irc_registration_override, recursive=True) }}"
  153. - name: Ensure Appservice IRC registration.yaml installed
  154. copy:
  155. content: "{{ matrix_appservice_irc_registration|to_nice_yaml(indent=2, width=999999) }}"
  156. dest: "{{ matrix_appservice_irc_config_path }}/registration.yaml"
  157. mode: 0644
  158. owner: "{{ matrix_user_username }}"
  159. group: "{{ matrix_user_groupname }}"
  160. - name: Ensure matrix-appservice-irc.service installed
  161. template:
  162. src: "{{ role_path }}/templates/systemd/matrix-appservice-irc.service.j2"
  163. dest: "{{ matrix_systemd_path }}/matrix-appservice-irc.service"
  164. mode: 0644
  165. register: matrix_appservice_irc_systemd_service_result
  166. - name: Ensure systemd reloaded after matrix-appservice-irc.service installation
  167. service:
  168. daemon_reload: true
  169. when: "matrix_appservice_irc_systemd_service_result.changed"
  170. - name: Ensure matrix-appservice-irc.service restarted, if necessary
  171. service:
  172. name: "matrix-appservice-irc.service"
  173. state: restarted
  174. when: "matrix_appservice_irc_requires_restart|bool"