From 2183d5778e4e4f086bc9b031577b6fde2fb0825b Mon Sep 17 00:00:00 2001 From: Salt Date: Thu, 23 Jul 2020 22:47:22 -0500 Subject: [PATCH] Add Postfix-SES role for easy integration --- roles/postfix-ses/handlers/main.yml | 8 ++++ roles/postfix-ses/meta/main.yml | 2 + roles/postfix-ses/tasks/main.yml | 47 ++++++++++++++++++++++ roles/postfix-ses/templates/main.cf | 52 +++++++++++++++++++++++++ roles/postfix-ses/templates/sasl_passwd | 1 + 5 files changed, 110 insertions(+) create mode 100644 roles/postfix-ses/handlers/main.yml create mode 100644 roles/postfix-ses/meta/main.yml create mode 100644 roles/postfix-ses/tasks/main.yml create mode 100644 roles/postfix-ses/templates/main.cf create mode 100644 roles/postfix-ses/templates/sasl_passwd diff --git a/roles/postfix-ses/handlers/main.yml b/roles/postfix-ses/handlers/main.yml new file mode 100644 index 0000000..e343753 --- /dev/null +++ b/roles/postfix-ses/handlers/main.yml @@ -0,0 +1,8 @@ +#!/usr/bin/ansible-playbook +# vim:ft=ansible: +--- +- name: restart postfix + systemd: + name: postfix + state: restarted + become: yes diff --git a/roles/postfix-ses/meta/main.yml b/roles/postfix-ses/meta/main.yml new file mode 100644 index 0000000..d098f75 --- /dev/null +++ b/roles/postfix-ses/meta/main.yml @@ -0,0 +1,2 @@ +--- +allow_duplicates: no diff --git a/roles/postfix-ses/tasks/main.yml b/roles/postfix-ses/tasks/main.yml new file mode 100644 index 0000000..6963548 --- /dev/null +++ b/roles/postfix-ses/tasks/main.yml @@ -0,0 +1,47 @@ +#!/usr/bin/ansible-playbook +# vim:ft=ansible: +--- +- name: Install Postfix for SES + block: + - name: Install Postfix + apt: + name: + - postfix + - name: Template out configuration + template: + src: "{{ item.src }}" + dest: "{{ item.dest }}" + mode: "{{ item.mode }}" + loop: + - { src: "main.cf", dest: "/etc/postfix/main.cf", mode: "0644" } + notify: restart postfix + - name: Template out password + template: + src: sasl_passwd + dest: /etc/postfix/sasl_passwd + mode: "0640" + owner: root + group: postfix + notify: restart postfix + register: p + - name: Look for password database + stat: + path: /etc/postfix/sasl_passwd.db + register: s + - name: Regenerate password database + command: + cmd: postmap /etc/postfix/sasl_passwd + notify: restart postfix + when: p is changed or not s.stat.exists + - name: Tighten permissions on sasl_passwd.db + file: + path: /etc/postfix/sasl_passwd.db + mode: "0640" + owner: root + group: postfix + - name: Enable service + systemd: + name: postfix + enabled: yes + state: started + become: yes diff --git a/roles/postfix-ses/templates/main.cf b/roles/postfix-ses/templates/main.cf new file mode 100644 index 0000000..3cba723 --- /dev/null +++ b/roles/postfix-ses/templates/main.cf @@ -0,0 +1,52 @@ +# See /usr/share/postfix/main.cf.dist for a commented, more complete version + + +# Debian specific: Specifying a file name will cause the first +# line of that file to be used as the name. The Debian default +# is /etc/mailname. +#myorigin = /etc/mailname + +smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu) +biff = no + +# appending .domain is the MUA's job. +append_dot_mydomain = no + +# Uncomment the next line to generate "delayed mail" warnings +#delay_warning_time = 4h + +readme_directory = no + +# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on +# fresh installs. +compatibility_level = 2 + +# TLS parameters +smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem +smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key +smtpd_use_tls=yes +smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache +smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache +# This section and the relayhost are set up for SES +smtp_sasl_auth_enable=yes +smtp_sasl_security_options = noanonymous +smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd +smtp_use_tls = yes +smtp_tls_security_level = encrypt +smtp_tls_note_starttls_offer = yes +smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt + +# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for +# information on enabling SSL in the smtp client. + +smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination +myhostname = web2.us-east-2.compute.internal +alias_maps = hash:/etc/aliases +alias_database = hash:/etc/aliases +mydestination = $myhostname, web2, localhost.localdomain, , localhost +relayhost = [email-smtp.us-east-1.amazonaws.com]:587 +mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 +mailbox_size_limit = 0 +recipient_delimiter = + +inet_interfaces = all +inet_protocols = all diff --git a/roles/postfix-ses/templates/sasl_passwd b/roles/postfix-ses/templates/sasl_passwd new file mode 100644 index 0000000..7dd36dd --- /dev/null +++ b/roles/postfix-ses/templates/sasl_passwd @@ -0,0 +1 @@ +[email-smtp.us-east-1.amazonaws.com]:587 {{ aws_ses_user }}:{{ aws_ses_pass }}