# SPDX-FileCopyrightText: 2026 Slavi Pantaleev # # SPDX-License-Identifier: AGPL-3.0-or-later --- - name: Prepare matrix-bot-draupnir Molecule tests hosts: all become: true vars_files: - "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/vars.yml" - "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/playbook-context.yml" gather_facts: true tasks: - name: Ensure apt cache is updated ansible.builtin.apt: update_cache: true cache_valid_time: 600 when: ansible_facts['os_family'] == 'Debian' - name: Ensure required packages are installed ansible.builtin.package: name: - python3-requests - fuse-overlayfs state: present - name: Ensure Docker is installed ansible.builtin.include_role: name: ansible-role-docker vars: docker_daemon_options: storage-driver: fuse-overlayfs # matrix-base creates this identity in the complete playbook. The component role's file # tasks resolve owner/group by name, so the role-scoped scenario supplies that side effect. - name: Ensure the matrix group exists ansible.builtin.group: name: "{{ matrix_group_name }}" gid: "{{ matrix_user_gid }}" state: present - name: Ensure the matrix user exists ansible.builtin.user: name: "{{ matrix_user_name }}" uid: "{{ matrix_user_uid }}" group: "{{ matrix_group_name }}" create_home: false system: true state: present - name: Ensure the base data path exists ansible.builtin.file: path: "{{ matrix_base_data_path }}" state: directory owner: "{{ matrix_user_name }}" group: "{{ matrix_group_name }}" mode: "0750" # Draupnir and the stub need the network before the role's converge creates it. - name: Ensure the container network the role attaches to exists ansible.builtin.command: argv: - docker - network - create - "{{ matrix_bot_draupnir_container_network }}" register: matrix_bot_draupnir_molecule_network changed_when: matrix_bot_draupnir_molecule_network.rc == 0 failed_when: - matrix_bot_draupnir_molecule_network.rc != 0 - "'already exists' not in matrix_bot_draupnir_molecule_network.stderr" # The bot must see itself joined to an existing management room. The create, member and # power-level events are the minimum state Draupnir needs to validate that room and prove # its own user can send state. No real homeserver or account is involved. - name: Ensure the homeserver stub is running with Draupnir management-room state ansible.builtin.include_tasks: file: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/tasks/homeserver-stub.yml" vars: molecule_shared_stub_network: "{{ matrix_bot_draupnir_container_network }}" molecule_shared_stub_user_id: "@draupnir:molecule.local" molecule_shared_stub_joined_rooms: - "{{ matrix_bot_draupnir_config_managementRoom }}" molecule_shared_stub_verbose: "1" molecule_shared_stub_room_state: - type: m.room.create state_key: '' room_id: "{{ matrix_bot_draupnir_config_managementRoom }}" sender: "@draupnir:molecule.local" event_id: "$molecule-create" origin_server_ts: 1 content: creator: "@draupnir:molecule.local" room_version: "10" - type: m.room.member state_key: "@draupnir:molecule.local" room_id: "{{ matrix_bot_draupnir_config_managementRoom }}" sender: "@draupnir:molecule.local" event_id: "$molecule-member" origin_server_ts: 2 content: displayname: Molecule Draupnir membership: join - type: m.room.power_levels state_key: '' room_id: "{{ matrix_bot_draupnir_config_managementRoom }}" sender: "@draupnir:molecule.local" event_id: "$molecule-power" origin_server_ts: 3 content: ban: 50 events_default: 0 invite: 50 kick: 50 redact: 50 state_default: 50 users: "@draupnir:molecule.local": 100 users_default: 0