2019-03-03 17:22:52 +00:00
---
2019-05-17 16:14:12 +00:00
2020-12-13 23:36:15 +00:00
- block :
- name : Check if an SQLite database already exists
stat :
2020-12-14 08:51:53 +00:00
path : "{{ matrix_appservice_discord_sqlite_database_path_local }}"
register : matrix_appservice_discord_sqlite_database_path_local_stat_result
2020-12-13 23:36:15 +00:00
- name : Fail if an SQLite database already exists when using Postgres
fail :
msg : >-
matrix_appservice_discord_database_engine has been set to `postgres` (which is our new default now).
2020-12-14 08:51:53 +00:00
However, we've discovered an existing SQLite database in {{ matrix_appservice_discord_sqlite_database_path_local }}.
2020-12-13 23:36:15 +00:00
It appears that you've been using this bridge with the SQLite engine until now.
2020-12-14 00:24:32 +00:00
To continue using SQLite, opt into it explicitly: add `matrix_appservice_discord_database_engine : sqlite` to your vars.yml file and re-run this same command.
Alternatively, to migrate your existing SQLite database to Postgres :
1 . Stop all services (`ansible-playbook -i inventory/hosts setup.yml --tags=stop`)
2020-12-14 08:51:53 +00:00
2 . Import the SQLite database into Postgres (`ansible-playbook -v -i inventory/hosts setup.yml --tags=import-generic-sqlite-db --extra-vars='sqlite_database_path={{ matrix_appservice_discord_sqlite_database_path_local }} postgres_db_connection_string={{ matrix_appservice_discord_database_connString }}'`)
2020-12-14 00:24:32 +00:00
3 . Re-run the playbook (`ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start`)
2020-12-14 08:51:53 +00:00
when : "matrix_appservice_discord_sqlite_database_path_local_stat_result.stat.exists"
2020-12-13 23:36:15 +00:00
when : "matrix_appservice_discord_database_engine == 'postgres'"
2019-03-03 17:22:52 +00:00
- name : Ensure Appservice Discord image is pulled
docker_image :
2019-03-05 07:20:36 +00:00
name : "{{ matrix_appservice_discord_docker_image }}"
2019-05-22 10:43:33 +00:00
source : "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
2019-06-10 11:23:51 +00: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 }}"
2019-03-03 17:22:52 +00:00
2019-06-26 07:30:51 +00:00
- name : Ensure AppService Discord paths exist
2019-03-03 17:22:52 +00:00
file :
2019-06-26 07:30:51 +00:00
path : "{{ item }}"
2019-03-03 17:22:52 +00:00
state : directory
mode : 0750
owner : "{{ matrix_user_username }}"
2020-05-01 17:59:32 +00:00
group : "{{ matrix_user_groupname }}"
2019-06-26 07:30:51 +00: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
stat :
path : "{{ matrix_appservice_discord_base_path }}/discord.db"
register : matrix_appservice_discord_stat_db
2019-03-03 17:22:52 +00:00
2019-06-26 07:30:51 +00:00
- name : (Data relocation) Ensure matrix-appservice-discord.service is stopped
service :
name : matrix-appservice-discord
state : stopped
daemon_reload : yes
failed_when : false
when : "matrix_appservice_discord_stat_db.stat.exists"
- name : (Data relocation) Move AppService Discord discord.db file to ./data directory
2019-08-01 11:40:12 +00:00
command : "mv {{ matrix_appservice_discord_base_path }}/{{ item }} {{ matrix_appservice_discord_data_path }}/{{ item }}"
with_items :
- discord.db
- user-store.db
- room-store.db
2019-06-26 07:30:51 +00:00
when : "matrix_appservice_discord_stat_db.stat.exists"
- name : Ensure AppService Discord config.yaml installed
2019-03-03 17:22:52 +00:00
copy :
content : "{{ matrix_appservice_discord_configuration|to_nice_yaml }}"
2019-06-26 07:30:51 +00:00
dest : "{{ matrix_appservice_discord_config_path }}/config.yaml"
2019-03-03 17:22:52 +00:00
mode : 0644
owner : "{{ matrix_user_username }}"
2020-05-01 17:59:32 +00:00
group : "{{ matrix_user_groupname }}"
2019-03-03 17:22:52 +00:00
2019-06-26 07:30:51 +00:00
- name : Ensure AppService Discord registration.yaml installed
copy :
content : "{{ matrix_appservice_discord_registration|to_nice_yaml }}"
dest : "{{ matrix_appservice_discord_config_path }}/registration.yaml"
mode : 0644
owner : "{{ matrix_user_username }}"
2020-05-01 17:59:32 +00:00
group : "{{ matrix_user_groupname }}"
2019-06-26 07:30:51 +00: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
shell : >-
2020-05-27 20:18:24 +00:00
{{ matrix_host_command_docker }} run --rm --name matrix-appservice-discord-link-gen
2019-06-26 07:30:51 +00:00
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
--cap-drop=ALL
2020-11-25 08:49:59 +00:00
--mount type=bind,src={{ matrix_appservice_discord_config_path }},dst=/cfg
2019-06-26 07:30:51 +00: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 17:22:52 +00:00
- name : Ensure matrix-appservice-discord.service installed
template :
2019-05-17 16:14:12 +00:00
src : "{{ role_path }}/templates/systemd/matrix-appservice-discord.service.j2"
2020-03-24 18:27:58 +00:00
dest : "{{ matrix_systemd_path }}/matrix-appservice-discord.service"
2019-03-03 17:22:52 +00:00
mode : 0644
2019-03-04 14:12:37 +00:00
register : matrix_appservice_discord_systemd_service_result
2019-03-05 07:10:15 +00:00
2019-03-04 14:12:37 +00:00
- name : Ensure systemd reloaded after matrix-appservice-discord.service installation
service :
daemon_reload : yes
2019-05-17 16:14:12 +00:00
when : "matrix_appservice_discord_systemd_service_result.changed"