Refactor postfix formula to work with arbitrary parameters

This commit is contained in:
Skyler Berg 2014-11-21 10:38:45 -08:00
parent a48a5fb499
commit 78f3a47bec
2 changed files with 34 additions and 41 deletions

View File

@ -20,26 +20,3 @@ include:
- watch_in: - watch_in:
- service: postfix - service: postfix
- template: jinja - template: jinja
- defaults:
smtpd_banner: {{ salt['pillar.get']('postfix:smtpd_banner', '$myhostname ESMTP $mail_name' )}}
biff: {{ salt['pillar.get']('postfix:biff', "'no'" )}}
append_dot_mydomain: {{ salt['pillar.get']('postfix:append_dot_mydomain', "'no'" )}}
readme_directory: {{ salt['pillar.get']('postfix:readme_directory', "'no'" )}}
smtpd_tls_cert_file: {{ salt['pillar.get']('postfix:smtpd_tls_cert_file', '/etc/ssl/certs/ssl-cert-snakeoil.pem' )}}
smtpd_tls_key_file: {{ salt['pillar.get']('postfix:smtpd_tls_key_file', '/etc/ssl/private/ssl-cert-snakeoil.key' )}}
smtpd_use_tls: {{ salt['pillar.get']('postfix:smtpd_use_tls', "'yes'" )}}
smtpd_tls_session_cache_database: {{ salt['pillar.get']('postfix:smtpd_tls_session_cache_database', 'btree:${data_directory}/smtpd_scache' )}}
smtp_tls_session_cache_database: {{ salt['pillar.get']('postfix:smtp_tls_session_cache_database', 'btree:${data_directory}/smtp_scache' )}}
myhostname: {{ salt['pillar.get']('postfix:myhostname', grains['fqdn'] )}}
alias_maps: {{ salt['pillar.get']('postfix:alias_maps', 'hash:/etc/aliases' )}}
alias_database: {{ salt['pillar.get']('postfix:alias_database', 'hash:/etc/aliases' )}}
mydestination: {{ salt['pillar.get']('postfix:mydestination', grains['fqdn'] + ', localhost.localdomain, ' + grains['domain'] )}}
relayhost: {{ salt['pillar.get']('postfix:relayhost', '' )}}
mynetworks: {{ salt['pillar.get']('postfix:mynetworks', '127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128' )}}
mailbox_size_limit: {{ salt['pillar.get']('postfix:mailbox_size_limit', '0' )}}
recipient_delimiter: {{ salt['pillar.get']('postfix:recipient_delimiter', '+' )}}
inet_interfaces: {{ salt['pillar.get']('postfix:inet_interfaces', 'all' )}}

View File

@ -1,3 +1,12 @@
{% set config = salt['pillar.get']('postfix', {}) -%}
{% set processed_parameters = [] -%}
{% macro set_parameter(parameter, default=None) -%}
{% set value = config.get(parameter, default) -%}
{% if value is not none -%}
{{ parameter }} = {{ value }}
{%- do processed_parameters.append(parameter) -%}
{% endif -%}
{% endmacro -%}
# Managed by config management # Managed by config management
# See /usr/share/postfix/main.cf.dist for a commented, more complete version # See /usr/share/postfix/main.cf.dist for a commented, more complete version
@ -7,36 +16,36 @@
# is /etc/mailname. # is /etc/mailname.
#myorigin = /etc/mailname #myorigin = /etc/mailname
smtpd_banner = {{ smtpd_banner }} {{ set_parameter('smtpd_banner', '$myhostname ESMTP $mail_name') }}
biff = {{ biff }} {{ set_parameter('biff', 'no') }}
# appending .domain is the MUA's job. # appending .domain is the MUA's job.
append_dot_mydomain = {{ append_dot_mydomain }} {{ set_parameter('append_dot_mydomain', 'no') }}
# Uncomment the next line to generate "delayed mail" warnings # Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h #delay_warning_time = 4h
readme_directory = {{ readme_directory }} {{ set_parameter('readme_directory', 'no') }}
# TLS parameters # TLS parameters
smtpd_tls_cert_file = {{ smtpd_tls_cert_file }} {{ set_parameter('smtpd_tls_cert_file', '/etc/ssl/certs/ssl-cert-snakeoil.pem') }}
smtpd_tls_key_file = {{ smtpd_tls_key_file }} {{ set_parameter('smtpd_tls_key_file', '/etc/ssl/private/ssl-cert-snakeoil.key') }}
smtpd_use_tls = {{ smtpd_use_tls }} {{ set_parameter('smtpd_use_tls', 'yes') }}
smtpd_tls_session_cache_database = {{ smtpd_tls_session_cache_database }} {{ set_parameter('smtpd_tls_session_cache_database', 'btree:${data_directory}/smtpd_scache') }}
smtp_tls_session_cache_database = {{ smtp_tls_session_cache_database }} {{ set_parameter('smtp_tls_session_cache_database', 'btree:${data_directory}/smtp_scache') }}
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client. # information on enabling SSL in the smtp client.
myhostname = {{ myhostname }} {{ set_parameter('myhostname', grains['fqdn']) }}
alias_maps = {{ alias_maps }} {{ set_parameter('alias_maps', 'hash:/etc/aliases') }}
alias_database = {{ alias_database }} {{ set_parameter('alias_database', 'hash:/etc/aliases') }}
mydestination = {{ mydestination }} {{ set_parameter('mydestination', grains['fqdn'] + ', localhost.localdomain, ' + grains['domain'] ) }}
relayhost = {{ relayhost }} {{ set_parameter('relayhost', '') }}
mynetworks = {{ mynetworks }} {{ set_parameter('mynetworks', '127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128') }}
mailbox_size_limit = {{ mailbox_size_limit }} {{ set_parameter('mailbox_size_limit', '0') }}
recipient_delimiter = {{ recipient_delimiter }} {{ set_parameter('recipient_delimiter', '+') }}
inet_interfaces = {{ inet_interfaces }} {{ set_parameter('inet_interfaces', 'all') }}
{% if 'virtual' in pillar.get('postfix','') %} {% if 'virtual' in pillar.get('postfix','') %}
virtual_alias_maps = hash:/etc/postfix/virtual virtual_alias_maps = hash:/etc/postfix/virtual
@ -44,3 +53,10 @@ virtual_alias_maps = hash:/etc/postfix/virtual
#TODO: move into a pillar #TODO: move into a pillar
message_size_limit = 41943040 message_size_limit = 41943040
{# Accept arbitrary parameters -#}
{% for parameter in config -%}
{% if parameter not in processed_parameters -%}
{{ set_parameter(parameter) }}
{% endif -%}
{% endfor -%}