diff --git a/roles/opensmtpd/README.md b/roles/opensmtpd/README.md new file mode 100644 index 0000000..5f28b4c --- /dev/null +++ b/roles/opensmtpd/README.md @@ -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. diff --git a/roles/opensmtpd/handlers/main.yml b/roles/opensmtpd/handlers/main.yml index e361a88..af59e17 100644 --- a/roles/opensmtpd/handlers/main.yml +++ b/roles/opensmtpd/handlers/main.yml @@ -1,5 +1,5 @@ - name: restart smtpd service: - name: smtpd + name: "{% if ansible_os_family == 'Alpine' %}smtpd{% else %}opensmtpd{% endif %}" state: restarted when: "'handler' not in ansible_skip_tags" diff --git a/roles/opensmtpd/tasks/main.yml b/roles/opensmtpd/tasks/main.yml index a29fd41..13cc8ba 100644 --- a/roles/opensmtpd/tasks/main.yml +++ b/roles/opensmtpd/tasks/main.yml @@ -1,17 +1,40 @@ -# this role is currently for alpine linux only - - name: Install mail server package: 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 template: dest: /etc/smtpd/smtpd.conf src: smtpd.conf.j2 + follow: true notify: restart smtpd +- name: Configure root mail alias + lineinfile: + path: /etc/smtpd/aliases + regexp: "^#? *root:" + line: "root: {{ mail_root }}" + - name: Enable mail server service: - name: smtpd + name: "{% if ansible_os_family == 'Alpine' %}smtpd{% else %}opensmtpd{% endif %}" enabled: yes state: started