Set up an Ansible environment for deploying Rocket.Chat to multiple servers.
See the Rocket.Chat official Ansible role.
Installation
Ansible works on a push model: your control node pushes configuration and ad hoc tasks to your systems over SSH, with no client software running on the systems you're deploying to. In other words, it's fast, efficient, secure, scalable, and highly portable. To control remote systems, you only need to install Ansible on your control node. Your desktop can serve as the control node you deploy from.
To learn more about Ansible installation on different operating systems, see the official installation guide.
Select the tab for your preferred installation method:
If you're using a UNIX-like operating system, such as Linux or BSD, Ansible is likely available in your official package repositories. Use your package manager to check for the package and install it. For example, on Debian-based systems:
sudo apt install ansibleAnsible is written in Python, so it's also available for installation via pip, Python's package manager. If you have pip installed, run the following command:
sudo pip install ansibleIf you don't have pip, check whether you can install it through your system's package manager. If you're on macOS and not using Homebrew or pkgsrc, you can install pip using easy_install:
sudo easy_install pip
sudo pip install ansibleSet up the deployment environment
With Ansible installed on your control node, you can now prepare the environment for deploying Rocket.Chat.
Prerequisites
Before you begin, verify the following:
You can access the target server via SSH as the
rootuser.The target server has Python installed and runs one of the following operating systems:
EL 7 (RHEL/CentOS)
Debian 8 (Jessie) LTS
Ubuntu 18.04 LTS
Ubuntu 19.04
Support for other operating systems and distributions may be added in future releases of the official Rocket.Chat Ansible role To request support for a particular OS, raise an issue in the repository.
Inventory set-up
The inventory file is a plain text file listing the systems you want Ansible to connect to and control. It can contain single hosts, host groups, groups of groups, and variables set for each host or group. To create your inventory:
Create a directory for your Ansible files and navigate to it. The directory can live anywhere on your system, for example, in your home directory or wherever you keep your code and Git repositories:
mkdir ansible cd ansibleWe recommend naming the directory
ansibleand the inventory fileinventoryso that your setup matches the commands used in this guide.Create the inventory file in that directory:
touch inventoryOpen the file and add your servers under a group. The
[chat_servers]line defines a group namedchat_servers. Any hostnames, FQDNs, or IP addresses listed under it become members of that group. Add the hostname or FQDN of the server you want to deploy Rocket.Chat to:[chat_servers] chat.my.domain
To deploy to more than one server, list each of them under the same group:[chat_servers] chat.my.domain talk.my.domainConfigure SSH authentication. We recommend authenticating SSH connections to your servers using SSH key pairs. If you can't use key pairs, you can temporarily provide the root user's password in the inventory file using the
ansible_ssh_passvariable:[chat_servers] chat.my.domain ansible_ssh_pass=<root-password> talk.my.domain
Replace<root-password>with the root user's password for that host.Storing a password in plain text in the inventory file is insecure. Use this method only temporarily, and switch to SSH key pairs as soon as possible.
Download the Rocket.Chat Ansible role
Ansible shares and reuses roles through Galaxy. You can download the roles you need with the ansible-galaxy command-line tool, which was installed together with Ansible. To download the Rocket.Chat role:
In your ansible directory, create a roles directory:
ansible $ mkdir rolesCreate a
roles/requirements.ymlfile. This file tellsansible-galaxyhow to fetch the role, and its contents depend on the version of Ansible you're running.Your title goes here
Your content goes here
Update
requirements.ymlwith the following content:- src: RocketChat.Server version: masterUpdate
requirements.ymlwith the following content:- src: RocketChat.Server version: v2.2.2
Fetch the Rocket.Chat Ansible role using the
ansible-galaxycommand:ansible-galaxy install -p roles/ -r roles/requirements.yml
This command installs the roles defined in requirements.yml. The RocketChat.Server role is now available in your roles directory. You can verify it:ls roles RocketChat.Server
Create a playbook for the Rocket.Chat Ansible role
Ansible roles are built from a collection of "plays", that is, tasks or actions to run. To use a role, create a playbook that tells Ansible to run the role on your systems. To create the playbook,
In your ansible directory, create a playbook file named
rocket_chat.yml:touch rocket_chat.ymlThe
.ymlextension denotes a YAML document, the format used to express most things in Ansible.Open the file and add the following content:
--- - name: Apply the RocketChat.Server role to all chat_servers hosts: chat_servers roles: - RocketChat.Server
This playbook applies the RocketChat.Server role to every host in the chat_servers group you defined in your inventory file.
Deploy Rocket.Chat using Ansible
Run the playbook with the
ansible-playbookcommand:ansible-playbook -i inventory rocket_chat.ymlThis command runs the
rocket_chat.ymlplaybook against the hosts listed in your inventory file.When the deployment completes, go to your server's address, for example, https://chat.my.domain. The Rocket.Chat login screen appears, confirming a successful deployment.