Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

91 строка
4.9 KiB

  1. # SPDX-FileCopyrightText: 2026 Slavi Pantaleev
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. # These fields are required on every entry, so that a bot's setup can be read off the definition without knowing what the playbook would otherwise default to.
  6. #
  7. # The optional `initial_managers` is deliberately not among them: it only overrides an instance-wide default, and demanding it on every bot would defeat that default's purpose.
  8. - name: Fail if a Meowlnir bot definition lacks required fields
  9. ansible.builtin.fail:
  10. msg: >-
  11. A bot definition in `matrix_bot_meowlnir_bots` is missing the `{{ item }}` field.
  12. Required on every entry: {{ matrix_bot_meowlnir_bot_required_fields | join(', ') }}.
  13. Offending definition: {{ bot | to_json }}
  14. when: "item not in bot"
  15. with_items: "{{ matrix_bot_meowlnir_bot_required_fields }}"
  16. - name: Fail if a Meowlnir bot username is empty
  17. ansible.builtin.fail:
  18. msg: "A bot definition in `matrix_bot_meowlnir_bots` has an empty `username`: {{ bot | to_json }}"
  19. when: "not bot.username"
  20. - name: Fail if Meowlnir bot username lacks the required prefix
  21. ansible.builtin.fail:
  22. msg: >-
  23. The Meowlnir bot username `{{ bot.username }}` does not start with
  24. `{{ matrix_bot_meowlnir_user_prefix }}`. Bot users need to fall within the user
  25. namespace declared in Meowlnir's appservice registration file, or the homeserver
  26. will refuse to let Meowlnir operate them.
  27. Either rename the bot, or adjust `matrix_bot_meowlnir_user_prefix`.
  28. when: "not bot.username.startswith(matrix_bot_meowlnir_user_prefix)"
  29. - name: Fail if a Meowlnir bot mixes management room auto-creation with declared rooms
  30. ansible.builtin.fail:
  31. msg: >-
  32. The Meowlnir bot `{{ bot.username }}` has `management_room_auto_create` enabled, but
  33. also declares `management_rooms`. These are mutually exclusive: either let the
  34. playbook create a management room, or declare the rooms yourself.
  35. when: "bot.management_room_auto_create | bool and bot.management_rooms | length > 0"
  36. - name: Fail if a Meowlnir bot has neither auto-created nor declared management rooms
  37. ansible.builtin.fail:
  38. msg: >-
  39. The Meowlnir bot `{{ bot.username }}` declares no `management_rooms` and does not have
  40. `management_room_auto_create` enabled, so there would be no room to command it from.
  41. Either create a room yourself and declare it, or enable `management_room_auto_create`.
  42. when: "not bot.management_room_auto_create | bool and bot.management_rooms | length == 0"
  43. - name: Fail if a Meowlnir bot declares `initial_managers` which is not a list
  44. ansible.builtin.fail:
  45. msg: >-
  46. The Meowlnir bot `{{ bot.username }}` declares an `initial_managers` value which is not
  47. a list. It needs to be a list of full Matrix user IDs (`@alice:example.com`), even when
  48. there is only one.
  49. Offending definition: {{ bot | to_json }}
  50. when: "'initial_managers' in bot and (bot.initial_managers is string or bot.initial_managers is mapping or bot.initial_managers is not iterable)"
  51. # Omitting the key inherits the instance-wide default; declaring it empty means nobody, which is why `default()` is used here without its `boolean` argument.
  52. - name: Determine the effective initial managers for a Meowlnir bot
  53. ansible.builtin.set_fact:
  54. matrix_bot_meowlnir_bot_initial_managers: "{{ bot.initial_managers | default(matrix_bot_meowlnir_initial_managers) }}"
  55. - name: Fail if Meowlnir management room auto-creation lacks an initial manager
  56. ansible.builtin.fail:
  57. msg: >-
  58. The Meowlnir bot `{{ bot.username }}` has `management_room_auto_create` enabled, but no
  59. initial managers are set, so nobody would be able to command the bot in the room that
  60. gets created.
  61. Either give the bot its own `initial_managers` list, or set
  62. `matrix_bot_meowlnir_initial_managers` (or the `matrix_admin` variable it follows by
  63. default), or disable `management_room_auto_create` and declare `management_rooms`
  64. yourself.
  65. when: "bot.management_room_auto_create | bool and matrix_bot_meowlnir_bot_initial_managers | length == 0"
  66. # Nothing downstream catches a bad value: the homeserver accepts invitations for users which do not exist, and on room versions supporting MSC4289 an invitee's standing in the room cannot be revoked afterwards.
  67. # So a typo here is both silent and permanent.
  68. - name: Fail if a Meowlnir initial manager is not a full Matrix user ID
  69. ansible.builtin.fail:
  70. msg: >-
  71. `{{ item }}` is listed as an initial manager for the Meowlnir bot `{{ bot.username }}`,
  72. but it is not a full Matrix user ID (`@alice:example.com`).
  73. when: "not (item.startswith('@') and ':' in item)"
  74. with_items: "{{ matrix_bot_meowlnir_bot_initial_managers }}"
  75. - name: Validate Meowlnir bot management rooms
  76. ansible.builtin.include_tasks: "{{ role_path }}/tasks/util/validate_bot_management_room.yml"
  77. with_items: "{{ bot.management_rooms }}"
  78. loop_control:
  79. loop_var: management_room