2019-03-03 18:22:52 +01:00
|
|
|
---
|
2019-05-17 18:14:12 +02:00
|
|
|
|
2022-07-18 09:39:08 +02:00
|
|
|
- ansible.builtin.set_fact:
|
2020-12-14 15:24:56 +01:00
|
|
|
matrix_appservice_discord_requires_restart: false
|
|
|
|
|
2022-09-27 10:38:33 +02:00
|
|
|
- when: "matrix_appservice_discord_database_engine == 'postgres'"
|
|
|
|
block:
|
2020-12-14 15:24:56 +01:00
|
|
|
- name: Check if an SQLite database already exists
|
2022-07-18 10:22:05 +02:00
|
|
|
ansible.builtin.stat:
|
2020-12-14 15:24:56 +01:00
|
|
|
path: "{{ matrix_appservice_discord_sqlite_database_path_local }}"
|
|
|
|
register: matrix_appservice_discord_sqlite_database_path_local_stat_result
|
|
|
|
|
2022-09-27 10:38:33 +02:00
|
|
|
- when: "matrix_appservice_discord_sqlite_database_path_local_stat_result.stat.exists | bool"
|
|
|
|
block:
|
2022-07-18 09:39:08 +02:00
|
|
|
- ansible.builtin.set_fact:
|
2022-11-27 06:23:41 +01:00
|
|
|
devture_postgres_db_migration_request:
|
2020-12-14 15:24:56 +01:00
|
|
|
src: "{{ matrix_appservice_discord_sqlite_database_path_local }}"
|
|
|
|
dst: "{{ matrix_appservice_discord_database_connString }}"
|
2022-07-18 10:22:05 +02:00
|
|
|
caller: "{{ role_path | basename }}"
|
2020-12-14 15:24:56 +01:00
|
|
|
engine_variable_name: 'matrix_appservice_discord_database_engine'
|
|
|
|
engine_old: 'sqlite'
|
|
|
|
systemd_services_to_stop: ['matrix-appservice-discord.service']
|
|
|
|
|
2022-07-18 15:15:04 +02:00
|
|
|
- ansible.builtin.import_role:
|
2022-11-27 06:23:41 +01:00
|
|
|
name: galaxy/com.devture.ansible.role.postgres
|
2022-07-18 15:15:04 +02:00
|
|
|
tasks_from: migrate_db_to_postgres
|
2020-12-14 15:24:56 +01:00
|
|
|
|
2022-07-18 09:39:08 +02:00
|
|
|
- ansible.builtin.set_fact:
|
2020-12-14 15:24:56 +01:00
|
|
|
matrix_appservice_discord_requires_restart: true
|
2020-12-14 00:36:15 +01:00
|
|
|
|
2019-03-03 18:22:52 +01:00
|
|
|
- name: Ensure Appservice Discord image is pulled
|
2022-10-28 13:20:17 +02:00
|
|
|
community.docker.docker_image:
|
2019-03-05 08:20:36 +01:00
|
|
|
name: "{{ matrix_appservice_discord_docker_image }}"
|
2019-05-22 12:43:33 +02:00
|
|
|
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
|
2019-06-10 13:23:51 +02:00
|
|
|
force_source: "{{ matrix_appservice_discord_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
|
|
|
|
force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_appservice_discord_docker_image_force_pull }}"
|
2022-03-17 16:37:11 +01:00
|
|
|
register: result
|
2022-11-04 15:44:29 +01:00
|
|
|
retries: "{{ devture_playbook_help_container_retries_count }}"
|
|
|
|
delay: "{{ devture_playbook_help_container_retries_delay }}"
|
2022-03-17 16:37:11 +01:00
|
|
|
until: result is not failed
|
2019-03-03 18:22:52 +01:00
|
|
|
|
2019-06-26 09:30:51 +02:00
|
|
|
- name: Ensure AppService Discord paths exist
|
2022-07-18 09:39:08 +02:00
|
|
|
ansible.builtin.file:
|
2019-06-26 09:30:51 +02:00
|
|
|
path: "{{ item }}"
|
2019-03-03 18:22:52 +01:00
|
|
|
state: directory
|
|
|
|
mode: 0750
|
|
|
|
owner: "{{ matrix_user_username }}"
|
2020-05-01 19:59:32 +02:00
|
|
|
group: "{{ matrix_user_groupname }}"
|
2019-06-26 09:30:51 +02:00
|
|
|
with_items:
|
|
|
|
- "{{ matrix_appservice_discord_base_path }}"
|
|
|
|
- "{{ matrix_appservice_discord_config_path }}"
|
|
|
|
- "{{ matrix_appservice_discord_data_path }}"
|
|
|
|
|
|
|
|
- name: Check if an old database file already exists
|
2022-07-18 10:22:05 +02:00
|
|
|
ansible.builtin.stat:
|
2019-06-26 09:30:51 +02:00
|
|
|
path: "{{ matrix_appservice_discord_base_path }}/discord.db"
|
|
|
|
register: matrix_appservice_discord_stat_db
|
2019-03-03 18:22:52 +01:00
|
|
|
|
2019-06-26 09:30:51 +02:00
|
|
|
- name: (Data relocation) Ensure matrix-appservice-discord.service is stopped
|
2022-07-18 09:39:08 +02:00
|
|
|
ansible.builtin.service:
|
2019-06-26 09:30:51 +02:00
|
|
|
name: matrix-appservice-discord
|
|
|
|
state: stopped
|
2022-02-05 21:32:54 +01:00
|
|
|
enabled: false
|
|
|
|
daemon_reload: true
|
2019-06-26 09:30:51 +02:00
|
|
|
failed_when: false
|
|
|
|
when: "matrix_appservice_discord_stat_db.stat.exists"
|
|
|
|
|
|
|
|
- name: (Data relocation) Move AppService Discord discord.db file to ./data directory
|
2022-07-18 09:39:08 +02:00
|
|
|
ansible.builtin.command: "mv {{ matrix_appservice_discord_base_path }}/{{ item }} {{ matrix_appservice_discord_data_path }}/{{ item }}"
|
2019-08-01 13:40:12 +02:00
|
|
|
with_items:
|
|
|
|
- discord.db
|
|
|
|
- user-store.db
|
|
|
|
- room-store.db
|
2019-06-26 09:30:51 +02:00
|
|
|
when: "matrix_appservice_discord_stat_db.stat.exists"
|
|
|
|
|
|
|
|
- name: Ensure AppService Discord config.yaml installed
|
2022-07-18 09:39:08 +02:00
|
|
|
ansible.builtin.copy:
|
2022-07-18 10:22:05 +02:00
|
|
|
content: "{{ matrix_appservice_discord_configuration | to_nice_yaml(indent=2, width=999999) }}"
|
2019-06-26 09:30:51 +02:00
|
|
|
dest: "{{ matrix_appservice_discord_config_path }}/config.yaml"
|
2019-03-03 18:22:52 +01:00
|
|
|
mode: 0644
|
|
|
|
owner: "{{ matrix_user_username }}"
|
2020-05-01 19:59:32 +02:00
|
|
|
group: "{{ matrix_user_groupname }}"
|
2019-03-03 18:22:52 +01:00
|
|
|
|
2019-06-26 09:30:51 +02:00
|
|
|
- name: Ensure AppService Discord registration.yaml installed
|
2022-07-18 09:39:08 +02:00
|
|
|
ansible.builtin.copy:
|
2022-07-18 10:22:05 +02:00
|
|
|
content: "{{ matrix_appservice_discord_registration | to_nice_yaml(indent=2, width=999999) }}"
|
2019-06-26 09:30:51 +02:00
|
|
|
dest: "{{ matrix_appservice_discord_config_path }}/registration.yaml"
|
|
|
|
mode: 0644
|
|
|
|
owner: "{{ matrix_user_username }}"
|
2020-05-01 19:59:32 +02:00
|
|
|
group: "{{ matrix_user_groupname }}"
|
2019-06-26 09:30:51 +02:00
|
|
|
|
|
|
|
# If `matrix_appservice_discord_client_id` hasn't changed, the same invite link would be generated.
|
|
|
|
# We intentionally suppress Ansible changes.
|
|
|
|
- name: Generate AppService Discord invite link
|
2022-07-18 09:39:08 +02:00
|
|
|
ansible.builtin.shell: >-
|
2022-11-04 15:39:35 +01:00
|
|
|
{{ devture_systemd_docker_base_host_command_docker }} run --rm --name matrix-appservice-discord-link-gen
|
2019-06-26 09:30:51 +02:00
|
|
|
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
|
|
|
|
--cap-drop=ALL
|
2020-11-25 09:49:59 +01:00
|
|
|
--mount type=bind,src={{ matrix_appservice_discord_config_path }},dst=/cfg
|
2019-06-26 09:30:51 +02:00
|
|
|
-w /cfg
|
|
|
|
{{ matrix_appservice_discord_docker_image }}
|
|
|
|
/bin/sh -c "node /build/tools/addbot.js > /cfg/invite_link"
|
|
|
|
changed_when: false
|
|
|
|
|
2019-03-03 18:22:52 +01:00
|
|
|
- name: Ensure matrix-appservice-discord.service installed
|
2022-07-18 09:39:08 +02:00
|
|
|
ansible.builtin.template:
|
2019-05-17 18:14:12 +02:00
|
|
|
src: "{{ role_path }}/templates/systemd/matrix-appservice-discord.service.j2"
|
2022-11-04 15:38:38 +01:00
|
|
|
dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-appservice-discord.service"
|
2019-03-03 18:22:52 +01:00
|
|
|
mode: 0644
|
2019-03-04 15:12:37 +01:00
|
|
|
register: matrix_appservice_discord_systemd_service_result
|
2019-03-05 08:10:15 +01:00
|
|
|
|
2019-03-04 15:12:37 +01:00
|
|
|
- name: Ensure systemd reloaded after matrix-appservice-discord.service installation
|
2022-07-18 09:39:08 +02:00
|
|
|
ansible.builtin.service:
|
2022-02-05 21:32:54 +01:00
|
|
|
daemon_reload: true
|
2019-05-17 18:14:12 +02:00
|
|
|
when: "matrix_appservice_discord_systemd_service_result.changed"
|
2020-12-14 15:24:56 +01:00
|
|
|
|
|
|
|
- name: Ensure matrix-appservice-discord.service restarted, if necessary
|
2022-07-18 09:39:08 +02:00
|
|
|
ansible.builtin.service:
|
2020-12-14 15:24:56 +01:00
|
|
|
name: "matrix-appservice-discord.service"
|
|
|
|
state: restarted
|
2022-07-18 10:22:05 +02:00
|
|
|
when: "matrix_appservice_discord_requires_restart | bool"
|