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.
 
 

81 lines
3.3 KiB

  1. ---
  2. - name: Ensure Appservice Discord image is pulled
  3. docker_image:
  4. name: "{{ matrix_appservice_discord_docker_image }}"
  5. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  6. force_source: "{{ matrix_appservice_discord_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_discord_docker_image_force_pull }}"
  8. - name: Ensure AppService Discord paths exist
  9. file:
  10. path: "{{ item }}"
  11. state: directory
  12. mode: 0750
  13. owner: "{{ matrix_user_username }}"
  14. group: "{{ matrix_user_username }}"
  15. with_items:
  16. - "{{ matrix_appservice_discord_base_path }}"
  17. - "{{ matrix_appservice_discord_config_path }}"
  18. - "{{ matrix_appservice_discord_data_path }}"
  19. - name: Check if an old database file already exists
  20. stat:
  21. path: "{{ matrix_appservice_discord_base_path }}/discord.db"
  22. register: matrix_appservice_discord_stat_db
  23. - name: (Data relocation) Ensure matrix-appservice-discord.service is stopped
  24. service:
  25. name: matrix-appservice-discord
  26. state: stopped
  27. daemon_reload: yes
  28. failed_when: false
  29. when: "matrix_appservice_discord_stat_db.stat.exists"
  30. # In addition to this, there used to be some `user-store-db` and `room-store.db` files.
  31. # They're no longer in use, so we're not relocating them in an effort to point them out as neither `./data`, nor `./config`.
  32. - name: (Data relocation) Move AppService Discord discord.db file to ./data directory
  33. command: "mv {{ matrix_appservice_discord_base_path }}/discord.db {{ matrix_appservice_discord_data_path }}/discord.db"
  34. when: "matrix_appservice_discord_stat_db.stat.exists"
  35. - name: Ensure AppService Discord config.yaml installed
  36. copy:
  37. content: "{{ matrix_appservice_discord_configuration|to_nice_yaml }}"
  38. dest: "{{ matrix_appservice_discord_config_path }}/config.yaml"
  39. mode: 0644
  40. owner: "{{ matrix_user_username }}"
  41. group: "{{ matrix_user_username }}"
  42. - name: Ensure AppService Discord registration.yaml installed
  43. copy:
  44. content: "{{ matrix_appservice_discord_registration|to_nice_yaml }}"
  45. dest: "{{ matrix_appservice_discord_config_path }}/registration.yaml"
  46. mode: 0644
  47. owner: "{{ matrix_user_username }}"
  48. group: "{{ matrix_user_username }}"
  49. # If `matrix_appservice_discord_client_id` hasn't changed, the same invite link would be generated.
  50. # We intentionally suppress Ansible changes.
  51. - name: Generate AppService Discord invite link
  52. shell: >-
  53. /usr/bin/docker run --rm --name matrix-appservice-discord-link-gen
  54. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  55. --cap-drop=ALL
  56. -v {{ matrix_appservice_discord_config_path }}:/cfg
  57. -w /cfg
  58. {{ matrix_appservice_discord_docker_image }}
  59. /bin/sh -c "node /build/tools/addbot.js > /cfg/invite_link"
  60. changed_when: false
  61. - name: Ensure matrix-appservice-discord.service installed
  62. template:
  63. src: "{{ role_path }}/templates/systemd/matrix-appservice-discord.service.j2"
  64. dest: "/etc/systemd/system/matrix-appservice-discord.service"
  65. mode: 0644
  66. register: matrix_appservice_discord_systemd_service_result
  67. - name: Ensure systemd reloaded after matrix-appservice-discord.service installation
  68. service:
  69. daemon_reload: yes
  70. when: "matrix_appservice_discord_systemd_service_result.changed"