From ebc25d7bbd92bba4a3d4fdf554a06be04233977d Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Sun, 30 Jan 2022 10:38:39 +0100 Subject: [PATCH] Importing exim4 role to better personalize it. --- roles/exim4/LICENSE.txt | 21 ++++++++++ roles/exim4/defaults/main.yml | 18 +++++++++ roles/exim4/handlers/main.yml | 6 +++ roles/exim4/tasks/configure.yml | 42 ++++++++++++++++++++ roles/exim4/tasks/install.yml | 6 +++ roles/exim4/tasks/main.yml | 17 ++++++++ roles/exim4/templates/email-addresses.j2 | 3 ++ roles/exim4/templates/exim4.conf.localmacros | 1 + roles/exim4/templates/passwd.client | 10 +++++ roles/exim4/templates/update-exim4.conf.conf | 30 ++++++++++++++ 10 files changed, 154 insertions(+) create mode 100755 roles/exim4/LICENSE.txt create mode 100644 roles/exim4/defaults/main.yml create mode 100644 roles/exim4/handlers/main.yml create mode 100644 roles/exim4/tasks/configure.yml create mode 100644 roles/exim4/tasks/install.yml create mode 100755 roles/exim4/tasks/main.yml create mode 100644 roles/exim4/templates/email-addresses.j2 create mode 100755 roles/exim4/templates/exim4.conf.localmacros create mode 100644 roles/exim4/templates/passwd.client create mode 100644 roles/exim4/templates/update-exim4.conf.conf diff --git a/roles/exim4/LICENSE.txt b/roles/exim4/LICENSE.txt new file mode 100755 index 0000000..248de00 --- /dev/null +++ b/roles/exim4/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 Tobias Schifftner, ambimax® GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/roles/exim4/defaults/main.yml b/roles/exim4/defaults/main.yml new file mode 100644 index 0000000..cf75b8a --- /dev/null +++ b/roles/exim4/defaults/main.yml @@ -0,0 +1,18 @@ +--- +exim4_sendonly_fqdn: '{{ ansible_fqdn }}' + +exim4_sendonly_enable_tls: true +exim4_sendonly_smarthost: '' +exim4_sendonly_username: '' +exim4_sendonly_password: '' + +exim4_sendonly_email_addresses: [] +# root: 'your@email.com' + +exim4_sendonly_email_aliases: [] +# - regexp: '^root:' +# line: 'root: your@email.com' + +exim4_sendonly_apt_packages: + - exim4-daemon-light + - mailutils diff --git a/roles/exim4/handlers/main.yml b/roles/exim4/handlers/main.yml new file mode 100644 index 0000000..130dd99 --- /dev/null +++ b/roles/exim4/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: restart exim4 + service: + name: 'exim4' + state: restarted + enabled: yes diff --git a/roles/exim4/tasks/configure.yml b/roles/exim4/tasks/configure.yml new file mode 100644 index 0000000..21d529e --- /dev/null +++ b/roles/exim4/tasks/configure.yml @@ -0,0 +1,42 @@ +--- + +- name: Configure exim4 + notify: restart exim4 + template: + src: 'update-exim4.conf.conf' + dest: /etc/exim4/update-exim4.conf.conf + +- name: Update mailname + notify: restart exim4 + copy: + content: '{{ exim4_sendonly_fqdn }}' + dest: '/etc/mailname' + +- name: Define email aliases + notify: restart exim4 + lineinfile: + dest: /etc/aliases + regexp: "{{ item.regexp }}" + line: "{{ item.line }}" + with_items: '{{ exim4_sendonly_email_aliases }}' + when: exim4_sendonly_email_aliases|length + +- name: Define email addresses + notify: restart exim4 + template: + src: 'email-addresses.j2' + dest: '/etc/email-addresses' + when: exim4_sendonly_email_addresses|length + +- name: Set auth for relay host + notify: restart exim4 + template: + src: 'passwd.client' + dest: '/etc/exim4/passwd.client' + +- name: Enable TLS + notify: restart exim4 + template: + src: 'exim4.conf.localmacros' + dest: '/etc/exim4/exim4.conf.localmacros' + when: exim4_sendonly_enable_tls diff --git a/roles/exim4/tasks/install.yml b/roles/exim4/tasks/install.yml new file mode 100644 index 0000000..9973a8a --- /dev/null +++ b/roles/exim4/tasks/install.yml @@ -0,0 +1,6 @@ +--- +- name: Install exim4 packages + apt: + name: '{{ exim4_sendonly_apt_packages }}' + state: present + cache_valid_time: 86400 diff --git a/roles/exim4/tasks/main.yml b/roles/exim4/tasks/main.yml new file mode 100755 index 0000000..30aaaa4 --- /dev/null +++ b/roles/exim4/tasks/main.yml @@ -0,0 +1,17 @@ +--- + +- name: Install exim4 + include: install.yml + tags: ['exim4-sendonly-install'] + +- name: Configure exim4 + include: configure.yml + tags: ['exim4-sendonly-configure'] + +- name: Start exim4 + service: + name: exim4 + state: started + enabled: true + changed_when: false + tags: ['always'] diff --git a/roles/exim4/templates/email-addresses.j2 b/roles/exim4/templates/email-addresses.j2 new file mode 100644 index 0000000..c7cbafe --- /dev/null +++ b/roles/exim4/templates/email-addresses.j2 @@ -0,0 +1,3 @@ +{% for user, email in exim4_sendonly_email_addresses.items() %} +{{ user }}: {{ email }} +{% endfor %} diff --git a/roles/exim4/templates/exim4.conf.localmacros b/roles/exim4/templates/exim4.conf.localmacros new file mode 100755 index 0000000..45836d7 --- /dev/null +++ b/roles/exim4/templates/exim4.conf.localmacros @@ -0,0 +1 @@ +MAIN_TLS_ENABLE = 1 \ No newline at end of file diff --git a/roles/exim4/templates/passwd.client b/roles/exim4/templates/passwd.client new file mode 100644 index 0000000..feeb0df --- /dev/null +++ b/roles/exim4/templates/passwd.client @@ -0,0 +1,10 @@ +# password file used when the local exim is authenticating to a remote +# host as a client. +# +# see exim4_passwd_client(5) for more documentation +# +# Example: +### target.mail.server.example:login:password +{% if exim4_sendonly_username != '' %} +*:{{ exim4_sendonly_username }}:{{ exim4_sendonly_password }} +{% endif %} diff --git a/roles/exim4/templates/update-exim4.conf.conf b/roles/exim4/templates/update-exim4.conf.conf new file mode 100644 index 0000000..0c29d5e --- /dev/null +++ b/roles/exim4/templates/update-exim4.conf.conf @@ -0,0 +1,30 @@ +# /etc/exim4/update-exim4.conf.conf +# +# Edit this file and /etc/mailname by hand and execute update-exim4.conf +# yourself or use 'dpkg-reconfigure exim4-config' +# +# Please note that this is _not_ a dpkg-conffile and that automatic changes +# to this file might happen. The code handling this will honor your local +# changes, so this is usually fine, but will break local schemes that mess +# around with multiple versions of the file. +# +# update-exim4.conf uses this file to determine variable values to generate +# exim configuration macros for the configuration file. +# +# Most settings found in here do have corresponding questions in the +# Debconf configuration, but not all of them. +# +# This is a Debian specific file +dc_eximconfig_configtype="{{ 'internet' if exim4_sendonly_smarthost == '' else 'satellite' }}" +dc_other_hostnames='{{ ansible_hostname }}; localhost.localdomain; localhost' +dc_local_interfaces='127.0.0.1' +dc_readhost='' +dc_relay_domains='' +dc_minimaldns='false' +dc_relay_nets='' +dc_smarthost='{{ exim4_sendonly_smarthost }}' +CFILEMODE='644' +dc_use_split_config='true' +dc_hide_mailname='true' +dc_mailname_in_oh='true' +dc_localdelivery='mail_spool'