feat(room): add initial role

This commit is contained in:
Jan Christian Grünhage 2022-11-27 21:58:49 +01:00
parent d0cbdf89d3
commit 14562d385e
No known key found for this signature in database
GPG key ID: EEC1170CE56FA2ED
5 changed files with 111 additions and 0 deletions

31
roles/room/README.md Normal file
View file

@ -0,0 +1,31 @@
# `famedly.matrix.room
Create and manage common room settings.
## Role Variables
### Mandatory
- `matrix_hs_url`: URL of the Matrix homeserver.
- `matrix_token`: Access token of the user that manages this room.
- `matrix_room_alias`: Full room alias of the room, including the server part.
### Optional
- `matrix_room_name`: Allows setting the room name.
- `matrix_room_topic`: Allows setting the room topic.
- `matrix_room_enable_encryption`: Allows enabling encryption for a room,
defaults to false. **Once enabled this can't be disabled again.**
- `matrix_room_join_rule`: Allows setting the join rule for the room. Related
to this, there is also `matrix_room_join_rules_restricted_allow` available.
For details, look at
https://spec.matrix.org/v1.5/client-server-api/#mroomjoin_rules.
- `matrix_room_additional_state`: Allows setting arbitrary additional state
events for a room. Takes an array of dicts, with the relevant keys being
`event_type`, `state_key` and `content`.
## License
AGPL-3.0-only
## Author Information
- `Jan Christian Grünhage <jan.christian@gruenhage.xyz>`

View file

@ -0,0 +1,12 @@
---
matrix_hs_url: ~
matrix_token: ~
matrix_room_alias: ~
matrix_room_name: ~
matrix_room_topic: ~
matrix_room_enable_encryption: false
matrix_room_join_rule: ~
matrix_room_join_rules_restricted_allow: []
# Array of dicts. Each event one dict, containing type, key and content
matrix_room_additional_state: []

9
roles/room/meta/main.yml Normal file
View file

@ -0,0 +1,9 @@
---
galaxy_info:
author: Jan Christian Grünhage
description: Manage Matrix rooms using Ansible
company: Famedly GmbH
license: AGPL-3.0-only
min_ansible_version: "2.12"
galaxy_tags: []
dependencies: []

23
roles/room/tasks/main.yml Normal file
View file

@ -0,0 +1,23 @@
---
- name: Collect Matrix auth info
ansible.builtin.meta: noop
vars: &matrix_auth
hs_url: "{{ matrix_hs_url }}"
token: "{{ matrix_token }}"
- name: Create room
famedly.matrix.matrix_room:
<<: *matrix_auth
alias: "{{ matrix_room_alias }}"
register: room_result
- name: Set up room state
famedly.matrix.matrix_state:
<<: *matrix_auth
room_id: "{{ room_result.room_id }}"
event_type: "{{ state.event_type }}"
state_key: "{{ state.state_key }}"
content: "{{ state.content }}"
loop_control:
loop_var: state
loop: "{{ matrix_room_merged_state }}"

36
roles/room/vars/main.yml Normal file
View file

@ -0,0 +1,36 @@
---
matrix_room_merged_state: |
{{
([join_rules_state] if matrix_room_join_rule else [])
+ ([room_name_state] if matrix_room_name else [])
+ ([room_topic_state] if matrix_room_topic else [])
+ ([encryption_state] if matrix_room_enable_encryption else [])
+ matrix_room_additional_state
}}
join_rules_state:
event_type: "m.room.join_rules"
state_key: ""
content: |
{{
{
'join_rule': matrix_room_join_rule
} | combine({
'allow': matrix_room_join_rules_restricted_allow
} if matrix_room_join_rule in ['restricted', 'knock_restricted'] else {})
}}
room_name_state:
event_type: "m.room.name"
state_key: ""
content: { name: "{{ matrix_room_name }}" }
room_topic_state:
event_type: "m.room.topic"
state_key: ""
content: { topic: "{{ matrix_room_topic }}" }
encryption_state:
event_type: "m.room.encryption"
state_key: ""
content: { algorithm: "m.megolm.v1.aes-sha2" }