mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2024-12-12 08:43:55 +02:00
99 lines
4.2 KiB
YAML
99 lines
4.2 KiB
YAML
---
|
|
|
|
- block:
|
|
- name: Check if an SQLite database already exists
|
|
stat:
|
|
path: "{{ matrix_appservice_discord_data_path }}/{{ matrix_appservice_discord_database_filename_name }}"
|
|
register: matrix_appservice_discord_stat_sqlite_db
|
|
|
|
- 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).
|
|
However, we've discovered an existing SQLite database in {{ matrix_appservice_discord_data_path }}/{{ matrix_appservice_discord_database_filename_name }}.
|
|
It appears that you've been using this bridge with the SQLite engine until now.
|
|
To continue using SQLite, opt into it explicitly: add `matrix_appservice_discord_database_engine: sqlite` to your vars.yml file.
|
|
To migrate to Postgres: TODO - migration instructions here.
|
|
when: "matrix_appservice_discord_database_engine == 'postgres'"
|
|
|
|
- name: Ensure Appservice Discord image is pulled
|
|
docker_image:
|
|
name: "{{ matrix_appservice_discord_docker_image }}"
|
|
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
|
|
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 }}"
|
|
|
|
- name: Ensure AppService Discord paths exist
|
|
file:
|
|
path: "{{ item }}"
|
|
state: directory
|
|
mode: 0750
|
|
owner: "{{ matrix_user_username }}"
|
|
group: "{{ matrix_user_groupname }}"
|
|
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
|
|
|
|
- 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
|
|
command: "mv {{ matrix_appservice_discord_base_path }}/{{ item }} {{ matrix_appservice_discord_data_path }}/{{ item }}"
|
|
with_items:
|
|
- discord.db
|
|
- user-store.db
|
|
- room-store.db
|
|
when: "matrix_appservice_discord_stat_db.stat.exists"
|
|
|
|
- name: Ensure AppService Discord config.yaml installed
|
|
copy:
|
|
content: "{{ matrix_appservice_discord_configuration|to_nice_yaml }}"
|
|
dest: "{{ matrix_appservice_discord_config_path }}/config.yaml"
|
|
mode: 0644
|
|
owner: "{{ matrix_user_username }}"
|
|
group: "{{ matrix_user_groupname }}"
|
|
|
|
- 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 }}"
|
|
group: "{{ matrix_user_groupname }}"
|
|
|
|
# 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: >-
|
|
{{ matrix_host_command_docker }} run --rm --name matrix-appservice-discord-link-gen
|
|
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
|
|
--cap-drop=ALL
|
|
--mount type=bind,src={{ matrix_appservice_discord_config_path }},dst=/cfg
|
|
-w /cfg
|
|
{{ matrix_appservice_discord_docker_image }}
|
|
/bin/sh -c "node /build/tools/addbot.js > /cfg/invite_link"
|
|
changed_when: false
|
|
|
|
- name: Ensure matrix-appservice-discord.service installed
|
|
template:
|
|
src: "{{ role_path }}/templates/systemd/matrix-appservice-discord.service.j2"
|
|
dest: "{{ matrix_systemd_path }}/matrix-appservice-discord.service"
|
|
mode: 0644
|
|
register: matrix_appservice_discord_systemd_service_result
|
|
|
|
- name: Ensure systemd reloaded after matrix-appservice-discord.service installation
|
|
service:
|
|
daemon_reload: yes
|
|
when: "matrix_appservice_discord_systemd_service_result.changed"
|