This guide deploys Mattermost Team Edition with Docker Compose on Debian 10 to latest stable, Ubuntu LTS, and RHEL 9+ compatible hosts.
- name: Deploy Mattermost
hosts: mattermost
become: true
vars:
app_root: /opt/mattermost
app_port: 8065
db_password: "{{ vault_mattermost_db_password }}"
site_url: "https://mattermost.example.com"
tasks:
- name: Install Docker on Debian/Ubuntu
apt:
name:
- docker.io
- docker-compose-plugin
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install Docker on RHEL family
dnf:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose-plugin
state: present
when: ansible_os_family == "RedHat"
- name: Enable and start Docker
service:
name: docker
state: started
enabled: true
- name: Create app directory
file:
path: "{{ app_root }}"
state: directory
mode: "0755"
- name: Write Docker Compose file
copy:
dest: "{{ app_root }}/docker-compose.yml"
mode: "0644"
content: |
version: '3.8'
services:
app:
image: mattermost/mattermost-team-edition:latest
container_name: mattermost
restart: unless-stopped
ports:
- "{{ app_port }}:8065"
environment:
- MM_SQLSETTINGS_DRIVERNAME=postgres
- MM_SQLSETTINGS_DATASOURCE=postgres://mmuser:{{ db_password }}@db:5432/mattermost?sslmode=disable
- MM_SERVICESETTINGS_SITEURL={{ site_url }}
volumes:
- ./volumes/app/mattermost/config:/mattermost/config
- ./volumes/app/mattermost/data:/mattermost/data
- ./volumes/app/mattermost/logs:/mattermost/logs
- ./volumes/app/mattermost/plugins:/mattermost/plugins
depends_on:
- db
db:
image: postgres:14
container_name: mattermost-db
restart: unless-stopped
environment:
- POSTGRES_USER=mmuser
- POSTGRES_PASSWORD={{ db_password }}
- POSTGRES_DB=mattermost
volumes:
- ./volumes/db:/var/lib/postgresql/data
- name: Start application stack
community.docker.docker_compose:
project_src: "{{ app_root }}"
state: present
- name: Wait for Mattermost to be ready
uri:
url: "http://localhost:{{ app_port }}/api/v4/system/ping"
status_code: 200
register: result
until: result.status == 200
retries: 30
delay: 5
Create an ansible-vault file with secure passwords:
# group_vars/all/vault.yml
vault_mattermost_db_password: "your-secure-database-password-here"
# Run the playbook
ansible-playbook -i inventory.ini mattermost.yml
# With vault password
ansible-playbook -i inventory.ini mattermost.yml --ask-vault-pass
For production deployments, consider adding:
Add these environment variables for email:
environment:
- MM_EMAILSETTINGS_SMTPSERVER=smtp.example.com
- MM_EMAILSETTINGS_SMTPPORT=587
- MM_EMAILSETTINGS_CONNECTIONSECURITY=STARTTLS
- MM_EMAILSETTINGS_USERNAME=smtp-user
- MM_EMAILSETTINGS_PASSWORD=smtp-password
See Configuration and Security for production hardening.
Any questions?
Feel free to contact us. Find all contact information on our contact page.