From 5a1f098597b82c0e198a9256a01171e2a2749ea0 Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Thu, 23 Apr 2020 01:44:57 +0000 Subject: [PATCH] Add postfix ansible roll --- ansible/postfix.yml | 6 ++ ansible/roles/postfix/README.md | 38 +++++++++++++ ansible/roles/postfix/defaults/main.yml | 8 +++ .../roles/postfix/files/postfix/init-mail.sh | 3 + ansible/roles/postfix/files/postfix/main.cf | 55 +++++++++++++++++++ .../roles/postfix/files/postfix/sasl_passwd | 1 + ansible/roles/postfix/handlers/main.yml | 7 +++ ansible/roles/postfix/meta/main.yml | 53 ++++++++++++++++++ ansible/roles/postfix/tasks/configure.yml | 20 +++++++ ansible/roles/postfix/tasks/install.yml | 4 ++ ansible/roles/postfix/tasks/main.yml | 7 +++ ansible/roles/postfix/tasks/service.yml | 3 + ansible/roles/postfix/vars/main.yml | 2 + 13 files changed, 207 insertions(+) create mode 100644 ansible/postfix.yml create mode 100644 ansible/roles/postfix/README.md create mode 100644 ansible/roles/postfix/defaults/main.yml create mode 100644 ansible/roles/postfix/files/postfix/init-mail.sh create mode 100644 ansible/roles/postfix/files/postfix/main.cf create mode 100644 ansible/roles/postfix/files/postfix/sasl_passwd create mode 100644 ansible/roles/postfix/handlers/main.yml create mode 100644 ansible/roles/postfix/meta/main.yml create mode 100644 ansible/roles/postfix/tasks/configure.yml create mode 100644 ansible/roles/postfix/tasks/install.yml create mode 100644 ansible/roles/postfix/tasks/main.yml create mode 100644 ansible/roles/postfix/tasks/service.yml create mode 100644 ansible/roles/postfix/vars/main.yml diff --git a/ansible/postfix.yml b/ansible/postfix.yml new file mode 100644 index 0000000..e88bbd2 --- /dev/null +++ b/ansible/postfix.yml @@ -0,0 +1,6 @@ +--- +- hosts: plumbi + become: yes + roles: + - postfix + diff --git a/ansible/roles/postfix/README.md b/ansible/roles/postfix/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/ansible/roles/postfix/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/ansible/roles/postfix/defaults/main.yml b/ansible/roles/postfix/defaults/main.yml new file mode 100644 index 0000000..4dd1af7 --- /dev/null +++ b/ansible/roles/postfix/defaults/main.yml @@ -0,0 +1,8 @@ +--- +# defaults file for /etc/ansible/roles/postfix +# +packages: [mailutils, postfix] +relay_host: "[sub.domain.com]:777" +email: "email@domain.com" +sasl_passwd: "xxxxxxxxxxxxx" + diff --git a/ansible/roles/postfix/files/postfix/init-mail.sh b/ansible/roles/postfix/files/postfix/init-mail.sh new file mode 100644 index 0000000..6d56b82 --- /dev/null +++ b/ansible/roles/postfix/files/postfix/init-mail.sh @@ -0,0 +1,3 @@ +sudo postmap /etc/postfix/sasl/sasl_passwd; +sudo chown root:root /etc/postfix/sasl/sasl_passwd /etc/postfix/sasl/sasl_passwd.db; +sudo chmod 600 /etc/postfix/sasl/sasl_passwd /etc/postfix/sasl/sasl_passwd.db; diff --git a/ansible/roles/postfix/files/postfix/main.cf b/ansible/roles/postfix/files/postfix/main.cf new file mode 100644 index 0000000..1b6418c --- /dev/null +++ b/ansible/roles/postfix/files/postfix/main.cf @@ -0,0 +1,55 @@ +# 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 + +# 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 = {{ ansible_hostname }} +alias_maps = hash:/etc/aliases +alias_database = hash:/etc/aliases +mydestination = $myhostname, {{ ansible_hostname }}, localhost.localdomain, localhost +relayhost = {{ relay_host }} +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 + +# Enable SASL authentication +smtp_sasl_auth_enable = yes +# Disallow methods that allow anonymous authentication +smtp_sasl_security_options = noanonymous +# Location of sasl_passwd +smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd +# Enable STARTTLS encryption +smtp_tls_security_level = encrypt +# Location of CA certificates +smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt diff --git a/ansible/roles/postfix/files/postfix/sasl_passwd b/ansible/roles/postfix/files/postfix/sasl_passwd new file mode 100644 index 0000000..67077ff --- /dev/null +++ b/ansible/roles/postfix/files/postfix/sasl_passwd @@ -0,0 +1 @@ +{{ relay_host }} {{ email }}:{{ sasl_passwd }} diff --git a/ansible/roles/postfix/handlers/main.yml b/ansible/roles/postfix/handlers/main.yml new file mode 100644 index 0000000..b6dac2d --- /dev/null +++ b/ansible/roles/postfix/handlers/main.yml @@ -0,0 +1,7 @@ +--- +# handlers file for /etc/ansible/roles/postfix +# + +- name: restart postfix + service: name=postfix state=restarted + diff --git a/ansible/roles/postfix/meta/main.yml b/ansible/roles/postfix/meta/main.yml new file mode 100644 index 0000000..4b0cae7 --- /dev/null +++ b/ansible/roles/postfix/meta/main.yml @@ -0,0 +1,53 @@ +galaxy_info: + author: Shaun Reed + description: A template for basic postfix configuration + company: (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.4 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. + diff --git a/ansible/roles/postfix/tasks/configure.yml b/ansible/roles/postfix/tasks/configure.yml new file mode 100644 index 0000000..fdcc49c --- /dev/null +++ b/ansible/roles/postfix/tasks/configure.yml @@ -0,0 +1,20 @@ +--- +- name: Copy postfix configuration template + template: src=files/postfix/main.cf dest=/etc/postfix/main.cf + +- name: Copy postfix sasl_passwd + template: src=files/postfix/sasl_passwd dest=/etc/postfix/sasl/sasl_passwd + +- name: Copy init-mail.sh script to remote hosts + copy: src=files/postfix/init-mail.sh dest=/etc/postfix/init-mail.sh + +- name: Touch a file, using symbolic modes to set the permissions (equivalent to 0644) + file: + path: /etc/postfix/init-mail.sh + state: touch + mode: u=rwx,g=rwx,o=rwx + +- name: Run script to initialize postfix + script: files/postfix/init-mail.sh + notify: + - restart postfix diff --git a/ansible/roles/postfix/tasks/install.yml b/ansible/roles/postfix/tasks/install.yml new file mode 100644 index 0000000..4233fc2 --- /dev/null +++ b/ansible/roles/postfix/tasks/install.yml @@ -0,0 +1,4 @@ +--- +- name: Install packages + apt: name="{{ item }}" state=latest + with_items: "{{ packages }}" diff --git a/ansible/roles/postfix/tasks/main.yml b/ansible/roles/postfix/tasks/main.yml new file mode 100644 index 0000000..7ba00f2 --- /dev/null +++ b/ansible/roles/postfix/tasks/main.yml @@ -0,0 +1,7 @@ +--- +# tasks file for /etc/ansible/roles/nginx + +- import_tasks: install.yml +- import_tasks: configure.yml +- import_tasks: service.yml + diff --git a/ansible/roles/postfix/tasks/service.yml b/ansible/roles/postfix/tasks/service.yml new file mode 100644 index 0000000..40e2109 --- /dev/null +++ b/ansible/roles/postfix/tasks/service.yml @@ -0,0 +1,3 @@ +--- +- name: Start and enable postfix service + service: name=postfix state=restarted enabled=yes diff --git a/ansible/roles/postfix/vars/main.yml b/ansible/roles/postfix/vars/main.yml new file mode 100644 index 0000000..7cc2c59 --- /dev/null +++ b/ansible/roles/postfix/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for /etc/ansible/roles/postfix