Files
CoM-ghost_protocol/phantom/playbooks/matrix/tasks/synapse.yml
T
n0mad1k 3542913689 LAN/local deployment support, OS compat, Cloudflare Tunnel
- Smart TLS: skip certbot for IPs/.local/.lan, self-signed with SAN,
  HSTS max-age=0 for self-signed certs, split LAN vs public messages
- Dynamic PHP: versionless meta-packages, runtime detection via php_ver fact
- Vaultwarden: fail-fast on armv7l (32-bit ARM not supported upstream)
- Module prompts: accept IPs for matrix/cloud/vault/media, hard error
  on email with IP, all_in_one skips certbot email for LAN
- Matrix: skip matrix. prefix strip for IPs, warn about immutable server_name
- OS family guards: ansible_os_family == Debian on all apt tasks
- SSH key path: expanduser().resolve() on user-provided key paths
- Cloudflare Tunnel: post-deploy script (setup-tunnel.sh) using CF API
  token — no browser auth needed, creates tunnel + credentials + DNS + systemd

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 13:27:12 -04:00

105 lines
2.5 KiB
YAML

---
# Synapse homeserver installation and configuration
# Uses SQLite3 (matches c2itall chat-server pattern — no PostgreSQL needed)
- name: Install dependencies
apt:
name:
- python3
- python3-pip
- python3-venv
- nginx
- certbot
- python3-certbot-nginx
- curl
- wget
- gnupg
- lsb-release
state: present
when: ansible_os_family == "Debian"
- name: Add Matrix Synapse GPG key and repository
shell: |
wget -qO /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/matrix-org.list
args:
creates: /etc/apt/sources.list.d/matrix-org.list
- name: Update apt cache after adding Matrix repo
apt:
update_cache: true
- name: Install Synapse
apt:
name: matrix-synapse-py3
state: present
environment:
DEBIAN_FRONTEND: noninteractive
- name: Set correct ownership for Matrix directories
file:
path: "{{ item }}"
state: directory
owner: matrix-synapse
group: matrix-synapse
mode: "0750"
recurse: true
loop:
- /var/lib/matrix-synapse
- /var/log/matrix-synapse
- name: Deploy Synapse homeserver config
template:
src: ../templates/homeserver.yaml.j2
dest: /etc/matrix-synapse/homeserver.yaml
owner: matrix-synapse
group: matrix-synapse
mode: "0640"
notify: restart synapse
- name: Clear conflicting conf.d configurations
shell: |
rm -f /etc/matrix-synapse/conf.d/*.yaml 2>/dev/null || true
changed_when: false
- name: Allow Matrix federation port through UFW
ufw:
rule: allow
port: "8448"
proto: tcp
- name: Allow HTTP/HTTPS through UFW
ufw:
rule: allow
port: "{{ item }}"
proto: tcp
loop:
- "80"
- "443"
- name: Enable and start Synapse
service:
name: matrix-synapse
state: restarted
enabled: true
- name: Wait for Synapse to be ready
wait_for:
port: 8008
host: 127.0.0.1
delay: 5
timeout: 60
- name: Create admin user
shell: |
/opt/venvs/matrix-synapse/bin/register_new_matrix_user \
-c /etc/matrix-synapse/homeserver.yaml \
-u {{ matrix_admin }} \
-p {{ matrix_admin_pass }} \
-a
register: admin_create
failed_when:
- admin_create.rc != 0
- "'User ID already taken' not in admin_create.stderr"
changed_when: "'User ID already taken' not in admin_create.stderr"