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.
 
 

100 lines
3.9 KiB

  1. ---
  2. - name: Ensure Appservice Discord image is pulled
  3. docker_image:
  4. name: "{{ matrix_appservice_discord_docker_image }}"
  5. when: "matrix_appservice_discord_enabled"
  6. - name: Ensure Appservice Discord configuration path exists
  7. file:
  8. path: "{{ matrix_appservice_discord_base_path }}"
  9. state: directory
  10. mode: 0750
  11. owner: "{{ matrix_user_username }}"
  12. group: "{{ matrix_user_username }}"
  13. when: "matrix_appservice_discord_enabled"
  14. - name: Ensure Matrix Appservice Discord config installed
  15. copy:
  16. content: "{{ matrix_appservice_discord_configuration|to_nice_yaml }}"
  17. dest: "{{ matrix_appservice_discord_base_path }}/config.yaml"
  18. mode: 0644
  19. owner: "{{ matrix_user_username }}"
  20. group: "{{ matrix_user_username }}"
  21. when: "matrix_appservice_discord_enabled"
  22. - name: Ensure matrix-appservice-discord.service installed
  23. template:
  24. src: "{{ role_path }}/templates/ext/appservice-discord/systemd/matrix-appservice-discord.service.j2"
  25. dest: "/etc/systemd/system/matrix-appservice-discord.service"
  26. mode: 0644
  27. register: matrix_appservice_discord_systemd_service_result
  28. when: "matrix_appservice_discord_enabled"
  29. - name: Ensure systemd reloaded after matrix-appservice-discord.service installation
  30. service:
  31. daemon_reload: yes
  32. when: "matrix_appservice_discord_enabled and matrix_appservice_discord_systemd_service_result.changed"
  33. - name: Check if a matrix-appservice-discord registration file exists
  34. stat:
  35. path: "{{ matrix_appservice_discord_base_path }}/discord-registration.yaml"
  36. register: appservice_discord_registration_file
  37. - name: Generate matrix-appservice-discord discord-registration.yaml if it doesn't exist
  38. shell: >-
  39. /usr/bin/docker run --rm --name matrix-appservice-discord-gen
  40. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  41. --cap-drop=ALL
  42. -v {{ matrix_appservice_discord_base_path }}:/data:z
  43. {{ matrix_appservice_discord_docker_image }}
  44. node build/src/discordas.js
  45. -r
  46. -u "http://matrix-appservice-discord:9005"
  47. -c /data/config.yaml
  48. -f /data/discord-registration.yaml
  49. -l discord_bot
  50. when: "matrix_appservice_discord_enabled and not appservice_discord_registration_file.stat.exists"
  51. - set_fact:
  52. matrix_synapse_app_service_config_file_appservice_discord: '{{ matrix_appservice_discord_base_path }}/discord-registration.yml'
  53. - name: Check if a matrix-appservice-discord invite_link file exists
  54. stat:
  55. path: "{{ matrix_appservice_discord_base_path }}/invite_link"
  56. register: appservice_discord_link_generated
  57. - name: Generate your discord invite link
  58. shell: >-
  59. /usr/bin/docker run --rm --name matrix-appservice-discord-link-gen
  60. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  61. --cap-drop=ALL
  62. -v {{ matrix_appservice_discord_base_path }}:/data
  63. -w /data
  64. {{ matrix_appservice_discord_docker_image }}
  65. /bin/sh -c "node .././build/tools/addbot.js > invite_link"
  66. when: "matrix_appservice_discord_enabled and not appservice_discord_link_generated.stat.exists"
  67. - set_fact:
  68. matrix_synapse_container_additional_volumes: >
  69. {{ matrix_synapse_container_additional_volumes }}
  70. +
  71. {{ [{'src': '{{ matrix_appservice_discord_base_path }}/discord-registration.yaml', 'dst': '{{ matrix_synapse_app_service_config_file_appservice_discord }}', 'options': 'ro'}] }}
  72. when: "matrix_appservice_discord_enabled"
  73. - set_fact:
  74. matrix_synapse_app_service_config_files: >
  75. {{ matrix_synapse_app_service_config_files }}
  76. +
  77. {{ ["{{ matrix_synapse_app_service_config_file_appservice_discord }}"] | to_nice_json }}
  78. when: "matrix_appservice_discord_enabled"
  79. #
  80. # Tasks related to getting rid of matrix-appservice-discord (if it was previously enabled)
  81. #
  82. - name: Ensure matrix-appservice-discord.service doesn't exist
  83. file:
  84. path: "/etc/systemd/system/matrix-appservice-discord.service"
  85. state: absent
  86. when: "not matrix_appservice_discord_enabled"