This Ansible playbook automates the deployment of Mail-in-a-Box mail server appliance on Ubuntu 22.04.
Create mailinabox-deploy.yml:
---
- name: Deploy Mail-in-a-Box
hosts: mailinabox
become: true
vars:
# Domain configuration
miab_domain: example.com
miab_hostname: mail.example.com
miab_email: admin@example.com
# Mail-in-a-Box configuration
miab_path: /opt/mailinabox
tasks:
# Verify Ubuntu version
- name: Verify Ubuntu 22.04
fail:
msg: "Mail-in-a-Box requires Ubuntu 22.04 LTS"
when: ansible_distribution != 'Ubuntu' or ansible_distribution_version != '22.04'
# Set hostname
- name: Set hostname
hostname:
name: "{{ miab_hostname }}"
- name: Update /etc/hosts
lineinfile:
path: /etc/hosts
line: "127.0.1.1 {{ miab_hostname }} {{ miab_hostname.split('.')[0] }}"
state: present
# Update system
- name: Update system packages
apt:
update_cache: yes
upgrade: dist
autoremove: yes
autoclean: yes
# Install prerequisites
- name: Install prerequisites
apt:
name:
- curl
- git
- wget
- unzip
- sudo
state: present
# Clone Mail-in-a-Box
- name: Clone Mail-in-a-Box repository
git:
repo: https://github.com/mail-in-a-box/mailinabox
dest: "{{ miab_path }}"
version: master
# Run Mail-in-a-Box installer
- name: Run Mail-in-a-Box installer
command: bash setup/start.sh
args:
chdir: "{{ miab_path }}"
environment:
NONINTERACTIVE: "1"
MAILINABOX_EMAIL: "{{ miab_email }}"
register: miab_install
changed_when: "'completed' in miab_install.stdout"
# Configure firewall
- name: Configure UFW firewall
ufw:
rule: allow
port: "{{ item }}"
proto: tcp
loop:
- "22" # SSH
- "25" # SMTP
- "587" # Submission
- "465" # SMTPS
- "143" # IMAP
- "993" # IMAPS
- "110" # POP3
- "995" # POP3S
- "80" # HTTP
- "443" # HTTPS
- name: Enable UFW
ufw:
state: enabled
# Reboot recommended after installation
- name: Recommend reboot
debug:
msg: "Installation complete. Reboot recommended with: sudo reboot"
Create inventory.ini:
[mailinabox]
mail.example.com ansible_user=root
[mailinabox:vars]
ansible_python_interpreter=/usr/bin/python3
# Run the playbook
ansible-playbook -i inventory.ini mailinabox-deploy.yml
# With custom variables
ansible-playbook -i inventory.ini mailinabox-deploy.yml \
-e miab_domain=example.com \
-e miab_hostname=mail.example.com \
-e miab_email=admin@example.com
| Variable | Default | Description |
|---|---|---|
miab_domain |
Required | Email domain |
miab_hostname |
Required | Mail server FQDN |
miab_email |
Required | Admin email |
miab_path |
/opt/mailinabox |
Installation directory |
https://mail.example.com/adminAt your domain registrar:
| Record Type | Name | Value |
|---|---|---|
| NS1 | (registrar) | ns1.example.com → Box IP |
| NS2 | (registrar) | ns2.example.com → Box IP |
⚠️ Ubuntu 22.04 Only: Mail-in-a-Box ONLY supports Ubuntu 22.04 LTS
⚠️ Fresh Installation: Requires clean Ubuntu installation
⚠️ No Docker: Mail-in-a-Box does not support Docker deployment
Any questions?
Feel free to contact us. Find all contact information on our contact page.