Matrix Docker Ansible eploy
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

150 wiersze
5.9 KiB

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