Compare commits

...

2 commits

Author SHA1 Message Date
7bb27acd2c opensmtpd: configure root mail alias
And add a README.
2025-08-11 14:07:45 +02:00
b64a5880b9 opensmtpd: add support for Debian 2025-08-11 14:04:58 +02:00
3 changed files with 30 additions and 4 deletions

View file

@ -0,0 +1,3 @@
Install opensmtpd and configure it for sending local mail through a relay.
The NetBox configuration context must define `mail_relay` with the relay hostname and `mail_root` with the email address where mail for root should be forwarded.

View file

@ -1,5 +1,5 @@
- name: restart smtpd - name: restart smtpd
service: service:
name: smtpd name: "{% if ansible_os_family == 'Alpine' %}smtpd{% else %}opensmtpd{% endif %}"
state: restarted state: restarted
when: "'handler' not in ansible_skip_tags" when: "'handler' not in ansible_skip_tags"

View file

@ -1,17 +1,40 @@
# this role is currently for alpine linux only
- name: Install mail server - name: Install mail server
package: package:
name: opensmtpd name: opensmtpd
# Alpine puts its configuration in /etc/smtpd, Debian in /etc
- when: ansible_os_family == 'Debian'
block:
- name: Create configuration directory
file:
path: /etc/smtpd
state: directory
- name: Link configuration
file:
path: "/etc/smtpd/{{ item }}"
src: "/etc/{{ item }}"
state: link
loop:
- smtpd.conf
- aliases
notify: restart smtpd
- name: Configure mail server - name: Configure mail server
template: template:
dest: /etc/smtpd/smtpd.conf dest: /etc/smtpd/smtpd.conf
src: smtpd.conf.j2 src: smtpd.conf.j2
follow: true
notify: restart smtpd notify: restart smtpd
- name: Configure root mail alias
lineinfile:
path: /etc/smtpd/aliases
regexp: "^#? *root:"
line: "root: {{ mail_root }}"
- name: Enable mail server - name: Enable mail server
service: service:
name: smtpd name: "{% if ansible_os_family == 'Alpine' %}smtpd{% else %}opensmtpd{% endif %}"
enabled: yes enabled: yes
state: started state: started