2024-05-25 21:11:17 +01:00
# mail-server
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.
2024-05-30 23:17:29 +01:00
## Ansible configurations
2024-05-25 21:11:17 +01:00
2024-05-30 23:17:29 +01:00
Available roles:
2024-05-25 21:11:17 +01:00
2024-05-30 23:17:29 +01:00
- 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.yml` for configuration
- secondary-mail.yml - sets up a secondary mail server, uses `vars-mx2.yml` for configuration
2024-05-25 21:11:17 +01:00
The hosts are taken from the `inventory.yml` file:
```yml
all:
hosts:
mx1:
2024-05-30 23:17:29 +01:00
ansible_host: < primary mail server ip >
2024-05-28 21:03:37 +01:00
mx2:
2024-05-29 20:06:22 +01:00
ansible_host: < secondary mail server ip >
2024-05-25 21:11:17 +01:00
```
## Environment setup
Install python on remote hosts:
```sh
# replace "mx1" with server name
ansible -m raw -i inventory.yml -u root -a "pkg_add python%3.8" mx1
```
Install required ansible collections:
```sh
ansible-galaxy collection install ansible.posix
ansible-galaxy collection install community.general
```
Run playbooks
```sh
2024-05-30 23:17:29 +01:00
# replace "secondary.yml" with the playbook you want to run
ansible-playbook -i inventory.yml secondary.yml
2024-05-25 21:11:17 +01:00
```