diff --git a/roles/mail_forwarder/molecule/default/tests/test_default.py b/roles/mail_forwarder/molecule/default/tests/test_default.py index 0a33b106ca3b33d7ab85d7576cab5a9b38bcfb39..397fd500065cc4dcad49846b79c2c249fb7a9e18 100644 --- a/roles/mail_forwarder/molecule/default/tests/test_default.py +++ b/roles/mail_forwarder/molecule/default/tests/test_default.py @@ -1,4 +1,5 @@ import os +import re import testinfra.utils.ansible_runner @@ -64,6 +65,22 @@ def test_postfix_main_cf_file(host): assert config.mode == 0o644 +def test_postfix_main_configuration_is_valid(host): + """ + Tests if Postfix main configuration is valid and not producing any + warnings. + """ + + postconf = host.run('/usr/sbin/postconf') + + # Clean-up the SSH warning from the beginning of stderr if + # present. + stderr = re.sub("^Warning: Permanently added.*?\r\n", "", postconf.stderr) + + assert postconf.rc == 0 + assert stderr == "" + + def test_services(host): """ Tests if all the necessary services are enabled and running. diff --git a/roles/mail_forwarder/templates/main.cf.j2 b/roles/mail_forwarder/templates/main.cf.j2 index 21277d5335937dffea5a7c01ab14e45a27c9e893..b27e2eb09cd8667f0adffce97fe025bb2c328ac0 100644 --- a/roles/mail_forwarder/templates/main.cf.j2 +++ b/roles/mail_forwarder/templates/main.cf.j2 @@ -23,10 +23,6 @@ inet_protocols = all # fails. Useful for local overrides of mail servers. smtp_host_lookup = dns, native -# Do not append server's domain to locally sent mail. This is up to -# sending MUAs to take care of. -append_dot_mydomain = no - # Recipient delimeter for separating user name from its extension. recipient_delimiter = + @@ -36,9 +32,15 @@ message_size_limit = {{ mail_message_size_limit }} # Disable output of Postfix README file paths when invoking postconf. readme_directory = no +{% if ansible_distribution_release != 'bullseye' %} +# Use whitelist/blacklist instead of allowlist/denylist in log +# entries. +respectful_logging = no +{% endif %} + # Compatibility level for default values. For more details, see: # https://www.postfix.org/COMPATIBILITY_README.html -compatibility_level = 2 +compatibility_level = 3.6 # Local mailbox delivery diff --git a/roles/mail_server/molecule/default/tests/test_default.py b/roles/mail_server/molecule/default/tests/test_default.py index 51d1855fdd64283fcdbb7e2883cd8b6a4fdc83ed..df02ca9dffe1b9e34e166dabc5ec4c210f2386b5 100644 --- a/roles/mail_server/molecule/default/tests/test_default.py +++ b/roles/mail_server/molecule/default/tests/test_default.py @@ -229,6 +229,22 @@ def test_postfix_main_cf_file(host): assert config.mode == 0o644 +def test_postfix_main_configuration_is_valid(host): + """ + Tests if Postfix main configuration is valid and not producing any + warnings. + """ + + postconf = host.run('/usr/sbin/postconf') + + # Clean-up the SSH warning from the beginning of stderr if + # present. + stderr = re.sub("^Warning: Permanently added.*?\r\n", "", postconf.stderr) + + assert postconf.rc == 0 + assert stderr == "" + + def test_postfix_delivery_to_dovecot(host): """ Tests if mail received by Postfix is properly delivered to Dovecot. diff --git a/roles/mail_server/templates/main.cf.j2 b/roles/mail_server/templates/main.cf.j2 index 7f83177c2c3f4d9e96e149f7695c775469a05d9c..af436cf335f845434d05b532faedb0be6b66f55b 100644 --- a/roles/mail_server/templates/main.cf.j2 +++ b/roles/mail_server/templates/main.cf.j2 @@ -23,10 +23,6 @@ inet_protocols = all # fails. Useful for local overrides of mail servers. smtp_host_lookup = dns, native -# Do not append server's domain to locally sent mail. This is up to -# sending MUAs to take care of. -append_dot_mydomain = no - # Recipient delimeter for separating user name from its extension. recipient_delimiter = + @@ -40,9 +36,15 @@ message_size_limit = {{ mail_message_size_limit }} # Disable output of Postfix README file paths when invoking postconf. readme_directory = no +{% if ansible_distribution_release != 'bullseye' %} +# Use whitelist/blacklist instead of allowlist/denylist in log +# entries. +respectful_logging = no +{% endif %} + # Compatibility level for default values. For more details, see: # https://www.postfix.org/COMPATIBILITY_README.html -compatibility_level = 2 +compatibility_level = 3.6 # Local mailbox delivery