From 200f13bc8f7d02f818deb6189904df4e73f183d6 Mon Sep 17 00:00:00 2001
From: Lars Beckers <lars.beckers@rwth-aachen.de>
Date: Wed, 24 Feb 2021 12:48:12 +0100
Subject: [PATCH] postfix: don't try to deploy undefined virtual aliases

---
 postfix/tasks/main.yml       | 1 +
 postfix/templates/main.cf.j2 | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/postfix/tasks/main.yml b/postfix/tasks/main.yml
index fb14d19..ad53dbf 100644
--- a/postfix/tasks/main.yml
+++ b/postfix/tasks/main.yml
@@ -103,6 +103,7 @@
   template:
     src: virtual.j2
     dest: /etc/postfix/virtual
+  when: virtual_aliases is defined or postfix_virtual_domains|count > 0
   notify:
     - postmap virtual
   tags:
diff --git a/postfix/templates/main.cf.j2 b/postfix/templates/main.cf.j2
index 784102c..346026e 100644
--- a/postfix/templates/main.cf.j2
+++ b/postfix/templates/main.cf.j2
@@ -84,7 +84,9 @@ tls_ssl_options = NO_COMPRESSION
 
 alias_maps = cdb:/etc/aliases
 alias_database = cdb:/etc/aliases
+{% if virtual_aliases is defined or postfix_virtual_domains|count > 0 %}
 virtual_alias_maps = cdb:/etc/postfix/virtual
+{% endif %}
 
 {% if postfix_virtual_domains|count > 0 %}
 virtual_mailbox_domains = {{ postfix_virtual_domains | join(", ") }}
-- 
GitLab