This guide deploys Rocket.Chat with Docker Compose on Debian 10 to latest stable, Ubuntu LTS, and RHEL 9+ compatible hosts. Rocket.Chat requires MongoDB with replica set enabled.
- name: Deploy Rocket.Chat
hosts: rocketchat
become: true
vars:
app_root: /opt/rocketchat
app_port: 3000
mongo_password: "{{ vault_rocketchat_mongo_password }}"
root_url: "https://chat.example.com"
mail_url: "smtp://smtp.example.com:587"
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:
rocketchat:
image: rocket.chat:latest
container_name: rocketchat
restart: unless-stopped
ports:
- "{{ app_port }}:3000"
environment:
- ROOT_URL={{ root_url }}
- MONGO_URL=mongodb://rocketchat:{{ mongo_password }}@db:27017/rocketchat
- MONGO_OPLOG_URL=mongodb://rocketchat:{{ mongo_password }}@db:27017/local
- MAIL_URL={{ mail_url }}
depends_on:
- db
volumes:
- ./uploads:/app/uploads
db:
image: mongo:8.0
container_name: rocketchat-db
restart: unless-stopped
command: mongod --replSet rs0 --oplogSize 128
volumes:
- ./dbdata:/data/db
environment:
- MONGO_INITDB_ROOT_USERNAME=rocketchat
- MONGO_INITDB_ROOT_PASSWORD={{ mongo_password }}
- name: Start application stack
community.docker.docker_compose:
project_src: "{{ app_root }}"
state: present
- name: Wait for MongoDB to start
wait_for:
timeout: 10
- name: Initialize MongoDB replica set
community.docker.docker_container_exec:
container: rocketchat-db
command: mongosh --username rocketchat --password {{ mongo_password }} --eval "rs.initiate({_id: 'rs0', members: [{_id: 0, host: 'localhost:27017'}]})"
register: rs_init
failed_when: "'ok' not in rs_init.stdout and 'already initialized' not in rs_init.stdout"
- name: Wait for Rocket.Chat to be ready
uri:
url: "http://localhost:{{ app_port }}/api/v1/info"
status_code: 200
register: result
until: result.status == 200
retries: 60
delay: 5
Create an ansible-vault file with secure passwords:
# group_vars/all/vault.yml
vault_rocketchat_mongo_password: "your-secure-mongo-password-here"
# Run the playbook
ansible-playbook -i inventory.ini rocketchat.yml
# With vault password
ansible-playbook -i inventory.ini rocketchat.yml --ask-vault-pass
For production deployments, consider adding:
Update the MAIL_URL variable with your SMTP settings:
vars:
mail_url: "smtp://username:password@smtp.example.com:587"
Rocket.Chat requires MongoDB replica set for the oplog (real-time updates). The playbook initializes a single-node replica set. For production, consider a 3-node replica set for high availability.
See Configuration and Security for production hardening.
Any questions?
Feel free to contact us. Find all contact information on our contact page.