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.
 
 

227 lines
8.9 KiB

  1. - name: Limit max upload size to 100MB part 1
  2. set_fact:
  3. matrix_synapse_max_upload_size_mb: "100"
  4. when: matrix_synapse_max_upload_size_mb_raw|int >= 100
  5. - name: Limit max upload size to 100MB part 2
  6. set_fact:
  7. matrix_synapse_max_upload_size_mb: "{{ matrix_synapse_max_upload_size_mb_raw }}"
  8. when: matrix_synapse_max_upload_size_mb_raw|int < 100
  9. - name: Record Synapse variables locally on AWX
  10. delegate_to: 127.0.0.1
  11. lineinfile:
  12. path: '{{ awx_cached_matrix_vars }}'
  13. regexp: "^#? *{{ item.key | regex_escape() }}:"
  14. line: "{{ item.key }}: {{ item.value }}"
  15. insertafter: '# Synapse Settings Start'
  16. with_dict:
  17. 'matrix_synapse_allow_public_rooms_over_federation': '{{ matrix_synapse_allow_public_rooms_over_federation }}'
  18. 'matrix_synapse_enable_registration': '{{ matrix_synapse_enable_registration }}'
  19. 'matrix_synapse_federation_enabled': '{{ matrix_synapse_federation_enabled }}'
  20. 'matrix_synapse_enable_group_creation': '{{ matrix_synapse_enable_group_creation }}'
  21. 'matrix_synapse_presence_enabled': '{{ matrix_synapse_presence_enabled }}'
  22. 'matrix_synapse_max_upload_size_mb': '{{ matrix_synapse_max_upload_size_mb }}'
  23. 'matrix_synapse_url_preview_enabled': '{{ matrix_synapse_url_preview_enabled }}'
  24. 'matrix_synapse_allow_guest_access': '{{ matrix_synapse_allow_guest_access }}'
  25. - name: Empty Synapse variable 'matrix_synapse_auto_join_rooms' locally on AWX, if raw inputs empty
  26. delegate_to: 127.0.0.1
  27. replace:
  28. path: '{{ awx_cached_matrix_vars }}'
  29. regexp: "^matrix_synapse_auto_join_rooms: .*$"
  30. replace: "matrix_synapse_auto_join_rooms: []"
  31. when: matrix_synapse_auto_join_rooms_raw|length == 0
  32. - name: If the raw inputs is not empty start constructing parsed auto_join_rooms list
  33. set_fact:
  34. matrix_synapse_auto_join_rooms_array: |-
  35. {{ matrix_synapse_auto_join_rooms_raw.splitlines() | to_json }}
  36. when: matrix_synapse_auto_join_rooms_raw|length > 0
  37. - name: Record Synapse variable 'matrix_synapse_auto_join_rooms' locally on AWX, if it's not blank
  38. delegate_to: 127.0.0.1
  39. lineinfile:
  40. path: '{{ awx_cached_matrix_vars }}'
  41. regexp: "^#? *{{ item.key | regex_escape() }}:"
  42. line: "{{ item.key }}: {{ item.value }}"
  43. insertafter: '# Synapse Settings Start'
  44. with_dict:
  45. "matrix_synapse_auto_join_rooms": "{{ matrix_synapse_auto_join_rooms_array }}"
  46. when: matrix_synapse_auto_join_rooms_raw|length > 0
  47. - name: Record Synapse Shared Secret if it's defined
  48. delegate_to: 127.0.0.1
  49. lineinfile:
  50. path: '{{ awx_cached_matrix_vars }}'
  51. regexp: "^#? *{{ item.key | regex_escape() }}:"
  52. line: "{{ item.key }}: {{ item.value }}"
  53. insertafter: '# Synapse Settings Start'
  54. with_dict:
  55. 'matrix_synapse_registration_shared_secret': '{{ ext_matrix_synapse_registration_shared_secret }}'
  56. when: ext_matrix_synapse_registration_shared_secret|length > 0
  57. - name: Record registations_require_3pid extra variable if true
  58. delegate_to: 127.0.0.1
  59. lineinfile:
  60. path: '{{ awx_cached_matrix_vars }}'
  61. regexp: "{{ item }}:"
  62. line: "{{ item }}"
  63. insertbefore: '# Synapse Extension End'
  64. with_items:
  65. - " registrations_require_3pid:"
  66. - " - email"
  67. when: ext_registrations_require_3pid|bool
  68. - name: Remove registrations_require_3pid extra variable if false
  69. delegate_to: 127.0.0.1
  70. lineinfile:
  71. path: '{{ awx_cached_matrix_vars }}'
  72. regexp: "{{ item }}:"
  73. line: "{{ item }}"
  74. insertbefore: '# Synapse Extension End'
  75. state: absent
  76. with_items:
  77. - " registrations_require_3pid:"
  78. - " - email"
  79. when: not ext_registrations_require_3pid|bool
  80. - name: Remove URL Languages
  81. delegate_to: 127.0.0.1
  82. replace:
  83. path: '{{ awx_cached_matrix_vars }}'
  84. regexp: '^(?!.*\bemail\b) - [a-zA-Z\-]{2,5}\n'
  85. after: ' url_preview_accept_language:'
  86. before: '# Synapse Extension End'
  87. - name: Set URL languages default if raw inputs empty
  88. set_fact:
  89. ext_url_preview_accept_language_default: 'en'
  90. when: ext_url_preview_accept_language_raw|length == 0
  91. - name: Set URL languages default if raw inputs not empty
  92. set_fact:
  93. ext_url_preview_accept_language_default: "{{ ext_url_preview_accept_language_raw }}"
  94. when: ext_url_preview_accept_language_raw|length > 0
  95. - name: Set URL languages if raw inputs empty
  96. delegate_to: 127.0.0.1
  97. lineinfile:
  98. path: '{{ awx_cached_matrix_vars }}'
  99. insertafter: '^ url_preview_accept_language:'
  100. line: " - {{ ext_url_preview_accept_language_default }}"
  101. when: ext_url_preview_accept_language_raw|length == 0
  102. - name: Set URL languages if raw inputs not empty
  103. delegate_to: 127.0.0.1
  104. lineinfile:
  105. path: '{{ awx_cached_matrix_vars }}'
  106. insertafter: '^ url_preview_accept_language:'
  107. line: " - {{ item }}"
  108. with_items: "{{ ext_url_preview_accept_language_raw.splitlines() }}"
  109. when: ext_url_preview_accept_language_raw|length > 0
  110. - name: Remove Federation Whitelisting 1
  111. delegate_to: 127.0.0.1
  112. replace:
  113. path: '{{ awx_cached_matrix_vars }}'
  114. regexp: '^ - [a-z0-9]+\.[a-z0-9.]+\n'
  115. after: ' federation_domain_whitelist:'
  116. before: '# Synapse Extension End'
  117. - name: Remove Federation Whitelisting 2
  118. delegate_to: 127.0.0.1
  119. lineinfile:
  120. path: '{{ awx_cached_matrix_vars }}'
  121. line: " federation_domain_whitelist:"
  122. state: absent
  123. - name: Set Federation Whitelisting 1
  124. delegate_to: 127.0.0.1
  125. lineinfile:
  126. path: '{{ awx_cached_matrix_vars }}'
  127. insertafter: '^matrix_synapse_configuration_extension_yaml: \|'
  128. line: " federation_domain_whitelist:"
  129. when: ext_federation_whitelist_raw|length > 0
  130. - name: Set Federation Whitelisting 2
  131. delegate_to: 127.0.0.1
  132. lineinfile:
  133. path: '{{ awx_cached_matrix_vars }}'
  134. insertafter: '^ federation_domain_whitelist:'
  135. line: " - {{ item }}"
  136. with_items: "{{ ext_federation_whitelist_raw.splitlines() }}"
  137. when: ext_federation_whitelist_raw|length > 0
  138. - name: Record Synapse Custom variables locally on AWX
  139. delegate_to: 127.0.0.1
  140. lineinfile:
  141. path: '{{ awx_cached_matrix_vars }}'
  142. regexp: "^#? *{{ item.key | regex_escape() }}:"
  143. line: "{{ item.key }}: {{ item.value }}"
  144. insertafter: '# Custom Settings Start'
  145. with_dict:
  146. 'ext_federation_whitelist_raw': '{{ ext_federation_whitelist_raw.splitlines() | to_json }}'
  147. 'ext_url_preview_accept_language_default': '{{ ext_url_preview_accept_language_default.splitlines() | to_json }}'
  148. - name: Set ext_recaptcha_public_key to a 'public-key' if undefined
  149. set_fact: ext_recaptcha_public_key="public-key"
  150. when: (ext_recaptcha_public_key is not defined) or (ext_recaptcha_public_key|length == 0)
  151. - name: Set ext_recaptcha_private_key to a 'private-key' if undefined
  152. set_fact: ext_recaptcha_private_key="private-key"
  153. when: (ext_recaptcha_private_key is not defined) or (ext_recaptcha_private_key|length == 0)
  154. - name: Record Synapse Extension variables locally on AWX
  155. delegate_to: 127.0.0.1
  156. lineinfile:
  157. path: '{{ awx_cached_matrix_vars }}'
  158. regexp: "^#? *{{ item.key | regex_escape() }}:"
  159. line: "{{ item.key }}: {{ item.value }}"
  160. insertbefore: '# Synapse Extension End'
  161. with_dict:
  162. ' enable_registration_captcha': '{{ ext_enable_registration_captcha }}'
  163. ' recaptcha_public_key': '{{ ext_recaptcha_public_key }}'
  164. ' recaptcha_private_key': '{{ ext_recaptcha_private_key }}'
  165. - name: Save new 'Configure Synapse' survey.json to the AWX tower, template
  166. delegate_to: 127.0.0.1
  167. template:
  168. src: 'roles/matrix-awx/surveys/configure_synapse.json.j2'
  169. dest: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}//configure_synapse.json'
  170. - name: Copy new 'Configure Synapse' survey.json to target machine
  171. copy:
  172. src: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/configure_synapse.json'
  173. dest: '/matrix/awx/configure_synapse.json'
  174. mode: '0660'
  175. - name: Collect AWX admin token the hard way!
  176. delegate_to: 127.0.0.1
  177. shell: |
  178. curl -sku {{ tower_username }}:{{ tower_password }} -H "Content-Type: application/json" -X POST -d '{"description":"Tower CLI", "application":null, "scope":"write"}' https://{{ tower_host }}/api/v2/users/1/personal_tokens/ | jq '.token' | sed -r 's/\"//g'
  179. register: tower_token
  180. no_log: True
  181. - name: Recreate 'Configure Synapse' job template
  182. delegate_to: 127.0.0.1
  183. awx.awx.tower_job_template:
  184. name: "{{ matrix_domain }} - 1 - Configure Synapse"
  185. description: "Configure Synapse (homeserver) settings."
  186. extra_vars: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/extra_vars.json') }}"
  187. job_type: run
  188. job_tags: "start,setup-synapse"
  189. inventory: "{{ member_id }}"
  190. project: "{{ member_id }} - Matrix Docker Ansible Deploy"
  191. playbook: setup.yml
  192. credential: "{{ member_id }} - AWX SSH Key"
  193. survey_enabled: true
  194. survey_spec: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/configure_synapse.json') }}"
  195. become_enabled: yes
  196. state: present
  197. verbosity: 1
  198. tower_host: "https://{{ tower_host }}"
  199. tower_oauthtoken: "{{ tower_token.stdout }}"
  200. validate_certs: yes