This repository contains the scripts, configuration files, and Ansible playbooks for my email server setup. After running my own email service for seven years and redoing the setup multiple times, I've decided to document everything here to streamline maintenance.
Feel free to read, copy, use, and suggest improvements.
Available roles:
- firewall - configures firewall
- initial-setup
- applies available system patches
- upgrades all installed packages
- installs nano and curl
- disables ssh password logins
- adds ssh public key
- mail-primary - installs and configures opensmtpd with dovecot and sive
- mail-secondary - installs and configures opensmtpd as a backup mail receiver
- prometheus-exporters - installs prometheus exporters
- ssl - generates ssl certificates and adds renew cron job
- vpn - configures wireguard vpn
Available playbooks:
- primary-mail.yml - sets up a primary mail server, uses
vars-mx1.ymlfor configuration - secondary-mail.yml - sets up a secondary mail server, uses
vars-mx2.ymlfor configuration
The hosts are taken from the inventory.yml file:
all:
hosts:
mx1:
ansible_host: <primary mail server ip>
mx2:
ansible_host: <secondary mail server ip>Install python on remote hosts:
# replace "mx1" with server name
ansible -m raw -i inventory.yml -u root -a "pkg_add python%3.8" mx1Install required ansible collections:
ansible-galaxy collection install ansible.posix
ansible-galaxy collection install community.generalRun playbooks
# replace "secondary.yml" with the playbook you want to run
ansible-playbook -i inventory.yml secondary.yml