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.
## Configuration
Ansible is used for configuration. The playbooks use a `vars.yml` file for settings. This file contains sensitive information, so it is not included in the repository. Below is an example of its structure:
```yml
---
ssh_public_key: "ssh-rsa AAAAB3...ak4EsUU="
mx1_domains:
- mx1.pikami.org
2024-05-28 21:03:37 +01:00
mx2_domains:
- mx2.pikami.org
mx1_mail_domain: mx1.pikami.org
mx2_mail_domain: mx2.pikami.org
2024-05-25 21:11:17 +01:00
mail_domains:
- pikami.net
- pikami.org
mail_users:
- user: bob@pikami.org
password: Password123
virtuals:
- "bob@pikami.net"
- "bob.coolman@pikami.net"
- user: alice@pikami.org
password: Password123
virtuals:
- "alice@pikami.net"
2024-05-29 20:06:22 +01:00
mx1_wg:
private_key: < wireguard private key >
address: < hosts address inside vpn >
port: 21841
interface: wg0
peers:
- name: Gateway
public_key: < vpn gateway public key >
endpoint: < gateway ip > :21841
allowed_ips: 10.2.0.1/32
mx2_wg:
private_key: < wireguard private key >
address: < hosts address inside vpn >
port: 21841
interface: wg0
peers:
- name: Gateway
public_key: < vpn gateway public key >
endpoint: < gateway ip > :21841
allowed_ips: 10.2.0.1/32
2024-05-25 21:11:17 +01:00
```
The hosts are taken from the `inventory.yml` file:
```yml
all:
hosts:
mx1:
2024-05-29 20:06:22 +01:00
ansible_host: < 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
# replace "01-initial_setup.yml" with the playbook you want to run
ansible-playbook -i inventory.yml 01-initial_setup.yml
```
Current ansible playbooks:
- 01-initial_setup.yml
- applies available system patches
- upgrades all installed packages
- installs nano, curl and git
- disables ssh password logins
- adds ssh public key
- 02-ssl.yml - generates ssl certificates and adds a renew cron job
- 03-mail.yml - installs and configures dovecot and opensmtpd
2024-05-28 21:03:37 +01:00
- 04-secondary-mail.yml - installs and configures opensmtpd as a backup mail receiver
2024-05-29 20:06:22 +01:00
- 05-vpn.yml - configures wireguard vpn