From 930f7c49742bf98537eedb0530f683d356aa00a6 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Mon, 30 Jan 2023 23:33:01 +0200 Subject: [PATCH] Add postfix config --- handlers/main.yml | 5 +++++ tasks/configure_postfix.yml | 16 ++++++++++++++++ tasks/main.yml | 3 +++ templates/mysql-virtual_forwardings_dbmail.cf.j2 | 5 +++++ 4 files changed, 29 insertions(+) create mode 100644 tasks/configure_postfix.yml create mode 100644 templates/mysql-virtual_forwardings_dbmail.cf.j2 diff --git a/handlers/main.yml b/handlers/main.yml index 1ec6a9b..52ae50c 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -2,3 +2,8 @@ - name: Reload systemd daemon systemd: daemon_reload: true + +- name: Restart postfix + service: + name: postfix + state: restarted diff --git a/tasks/configure_postfix.yml b/tasks/configure_postfix.yml new file mode 100644 index 0000000..ecf4f6a --- /dev/null +++ b/tasks/configure_postfix.yml @@ -0,0 +1,16 @@ +--- +- name: Create MySQL virtual forwardings map file + template: + path: /etc/postfix/mysql-virtual_forwardings_dbmail.cf + src: mysql-virtual_forwardings_dbmail.cf.j2 + notify: Restart postfix + +- name: Configure Postfix virtual mailbox maps + lineinfile: + path: /etc/postfix/main.cf + regexp: '^virtual_mailbox_domains = ' + line: virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf proxy:mysql:/etc/postfix/mysql-virtual_forwardings_dbmail.cf + backup: true + notify: Restart postfix + + diff --git a/tasks/main.yml b/tasks/main.yml index e6cf9bb..a1b88ec 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -21,3 +21,6 @@ - name: Ensure user's are configured in dbmail include_tasks: configure_dbmail_users.yml + +- name: Ensure postfix is configured for dbmail + include_tasks: configure_postfix.yml diff --git a/templates/mysql-virtual_forwardings_dbmail.cf.j2 b/templates/mysql-virtual_forwardings_dbmail.cf.j2 new file mode 100644 index 0000000..e97173d --- /dev/null +++ b/templates/mysql-virtual_forwardings_dbmail.cf.j2 @@ -0,0 +1,5 @@ +user = {{ dbmail_db_user}} +password = {{ dbmail_db_password }} +dbname = {{ dbmail_db_name }} +query = SELECT DISTINCT 1 FROM dbmail_aliases WHERE SUBSTRING_INDEX(alias, '@', -1) = '%s'; +hosts = 127.0.0.1