This Ansible playbook automates the traditional (non-Docker) installation of iRedMail mail server solution.
For Docker-based deployment, see iRedMail Docker Ansible.
Create iredmail-deploy.yml:
---
- name: Deploy iRedMail mail server
hosts: iredmail
become: true
vars:
# Domain configuration
iredmail_domain: example.com
iredmail_hostname: mail.example.com
# Admin credentials
iredmail_admin_password: "secure_admin_password"
# Database configuration
iredmail_db_backend: mariadb
mariadb_root_password: "secure_mariadb_root_password"
iredmail_db_password: "secure_iredmail_password"
# Web server
iredmail_webserver: nginx
# Webmail
iredmail_webmail: roundcube
tasks:
# Download iRedMail
- name: Download iRedMail
get_url:
url: https://github.com/iredmail/iRedMail/archive/refs/heads/master.zip
dest: /tmp/iRedMail-master.zip
mode: '0644'
- name: Extract iRedMail
unarchive:
src: /tmp/iRedMail-master.zip
dest: /tmp
remote_src: yes
# Set hostname
- name: Set hostname
hostname:
name: "{{ iredmail_hostname }}"
- name: Update /etc/hosts
lineinfile:
path: /etc/hosts
line: "127.0.1.1 {{ iredmail_hostname }} {{ iredmail_hostname.split('.')[0] }}"
state: present
# Create iRedMail configuration
- name: Create iRedMail auto configuration
copy:
dest: /tmp/iRedMail-master/auto.conf
mode: '0600'
content: |
export STORAGE_BASE="/var/vmail"
export STORAGE_DB_BACKEND="{{ iredmail_db_backend }}"
export STORAGE_DB_ROOT_PASSWORD="{{ mariadb_root_password }}"
export STORAGE_DB_PASSWORD="{{ iredmail_db_password }}"
export WEB_SERVER="{{ iredmail_webserver }}"
export WEBMAIL="{{ iredmail_webmail }}"
export FIRST_DOMAIN="{{ iredmail_domain }}"
export ADMIN_EMAIL="postmaster@{{ iredmail_domain }}"
export ADMIN_PASSWORD="{{ iredmail_admin_password }}"
export SSL_CERT_GENERATOR="lets"
export BACKUP_MX="n"
export USE_WIZARD="n"
# Run iRedMail installer
- name: Run iRedMail installer
command: bash iRedMail.sh
args:
chdir: /tmp/iRedMail-master
environment:
STORAGE_BASE: "/var/vmail"
STORAGE_DB_BACKEND: "{{ iredmail_db_backend }}"
STORAGE_DB_ROOT_PASSWORD: "{{ mariadb_root_password }}"
STORAGE_DB_PASSWORD: "{{ iredmail_db_password }}"
WEB_SERVER: "{{ iredmail_webserver }}"
WEBMAIL: "{{ iredmail_webmail }}"
FIRST_DOMAIN: "{{ iredmail_domain }}"
ADMIN_EMAIL: "postmaster@{{ iredmail_domain }}"
ADMIN_PASSWORD: "{{ iredmail_admin_password }}"
SSL_CERT_GENERATOR: "lets"
register: iredmail_install
changed_when: "'Successfully' in iredmail_install.stdout"
# Configure firewall
- name: Configure UFW firewall
ufw:
rule: allow
port: "{{ item }}"
proto: tcp
loop:
- "25"
- "587"
- "465"
- "143"
- "993"
- "110"
- "995"
- "80"
- "443"
# Enable services
- name: Enable and start services
systemd:
name: "{{ item }}"
state: started
enabled: true
loop:
- postfix
- dovecot
- mariadb
- nginx
- clamav-daemon
- rspamd
handlers:
- name: restart nginx
systemd:
name: nginx
state: restarted
- name: restart postfix
systemd:
name: postfix
state: restarted
- name: restart dovecot
systemd:
name: dovecot
state: restarted
Create inventory.ini:
[iredmail]
mail.example.com ansible_user=root
[iredmail:vars]
ansible_python_interpreter=/usr/bin/python3
# Run the playbook
ansible-playbook -i inventory.ini iredmail-deploy.yml
# With custom variables
ansible-playbook -i inventory.ini iredmail-deploy.yml \
-e iredmail_domain=example.com \
-e iredmail_hostname=mail.example.com \
-e iredmail_admin_password="super_secure_password"
| Variable | Default | Description |
|---|---|---|
iredmail_domain |
Required | Email domain |
iredmail_hostname |
Required | Mail server FQDN |
iredmail_admin_password |
Required | iRedAdmin password |
iredmail_db_backend |
mariadb |
Database (mariadb/mysql/postgresql/ldap) |
mariadb_root_password |
Required | MariaDB root password |
iredmail_db_password |
Required | Database user password |
iredmail_webserver |
nginx |
Web server (nginx/apache) |
iredmail_webmail |
roundcube |
Webmail (roundcube/sogo) |
https://mail.example.com/iredadmin/postmaster@example.com# A Record
mail.example.com. IN A <server-ip>
# MX Record
example.com. IN MX 10 mail.example.com.
# SPF Record
example.com. IN TXT "v=spf1 mx a -all"
# DKIM Record (get from iRedAdmin)
dkim._domainkey.example.com. IN TXT "v=DKIM1; k=rsa; p=..."
# DMARC Record
_dmarc.example.com. IN TXT "v=DMARC1; p=quarantine"
Any questions?
Feel free to contact us. Find all contact information on our contact page.