5
0
mirror of https://github.com/spantaleev/matrix-docker-ansible-deploy.git synced 2026-08-15 21:30:51 +00:00
Files
matrix-docker-ansible-deploy/roles/custom/matrix-bot-meowlnir/tasks/util/prune_bots.yml
T
Slavi Pantaleev f9222dc70c Add support for Meowlnir
Meowlnir (https://github.com/maunium/meowlnir) is a Matrix moderation
bot which speaks the same policy-list protocol as Mjolnir and Draupnir,
but runs as an appservice and can override individual policies coming
from ban lists you do not control.

Bots and their management rooms live only in Meowlnir's own database —
nothing in its configuration file can declare one — so the role
provisions them through the management API from a declarative roster
(matrix_bot_meowlnir_bots_custom), applied under the
ensure-matrix-users-created tag. Management rooms may be declared or
created for you; bots and rooms no longer declared get pruned.

Wrapper scripts for driving the management API by hand are installed
to /matrix/meowlnir/bin.

Meowlnir re-runs its configuration upgrader in memory on every start,
so a literal `generate` value yields a new secret per restart. All
secrets are therefore rendered explicitly, validation rejects
`generate`, and the configuration directory is mounted read-only.

Draupnir and Meowlnir both want synapse-http-antispam, which the
playbook wires up to a single consumer. The wiring prefers Draupnir,
and both roles fail the run when each claims it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-13 06:05:30 +03:00

51 lines
2.2 KiB
YAML

# SPDX-FileCopyrightText: 2026 Slavi Pantaleev
#
# SPDX-License-Identifier: AGPL-3.0-or-later
---
# Makes the declared bot list authoritative: anything Meowlnir still knows about but which is no longer declared gets removed.
# Meowlnir's own records are re-read first, because the provisioning that just ran will have changed them.
- name: Re-read Meowlnir's bots before pruning
ansible.builtin.include_tasks: "{{ role_path }}/tasks/util/read_meowlnir_state.yml"
- name: Determine which Meowlnir bots are no longer declared
ansible.builtin.set_fact:
matrix_bot_meowlnir_undeclared_bots: >-
{{
matrix_bot_meowlnir_live_bots
| rejectattr('username', 'in', matrix_bot_meowlnir_bots | map(attribute='username') | list)
| list
}}
- name: Fail if pruning would remove every Meowlnir bot
ansible.builtin.fail:
msg: >-
No bots are declared in `matrix_bot_meowlnir_bots`, but Meowlnir still has
{{ matrix_bot_meowlnir_undeclared_bots | length }} of them
({{ matrix_bot_meowlnir_undeclared_bots | map(attribute='username') | join(', ') }}).
Removing them would make Meowlnir forget them along with their management rooms, so the
playbook will not act on what is far more often a mistake (a commented-out block, an
unset variable) than an instruction.
If you really do want them all gone, set
`matrix_bot_meowlnir_bots_pruning_on_empty_roster_enabled: true`.
To stop the playbook managing bots at all, set
`matrix_bot_meowlnir_bots_pruning_enabled: false`.
when: >-
matrix_bot_meowlnir_bots | length == 0
and matrix_bot_meowlnir_undeclared_bots | length > 0
and not matrix_bot_meowlnir_bots_pruning_on_empty_roster_enabled | bool
- name: Remove management rooms which are no longer declared
ansible.builtin.include_tasks: "{{ role_path }}/tasks/util/prune_bot_management_rooms.yml"
with_items: "{{ matrix_bot_meowlnir_live_bots }}"
loop_control:
loop_var: live_bot
- name: Remove Meowlnir bots which are no longer declared
ansible.builtin.include_tasks: "{{ role_path }}/tasks/util/prune_bot.yml"
with_items: "{{ matrix_bot_meowlnir_undeclared_bots }}"
loop_control:
loop_var: live_bot