From 2cd7aa66fc03eb027f11376dcfc665a085ff6c21 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 29 Feb 2016 16:00:07 +0100 Subject: [PATCH] Adding states for postfix mappings --- postfix/common.sls | 47 +++++++++++++++++++++++++++++++++++++++-- postfix/files/main.cf | 2 +- postfix/files/smtp_auth | 14 ++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 postfix/files/smtp_auth diff --git a/postfix/common.sls b/postfix/common.sls index eed0798..2d881f7 100644 --- a/postfix/common.sls +++ b/postfix/common.sls @@ -56,7 +56,7 @@ postfix.pem: - file: /etc/postfix/postfix-cert.cnf # manage /etc/aliases if data found in pillar -{% if 'aliases' in pillar.get('postfix', '') %} +{% if 'aliases' in pillar.get('postfix', '') -%} {{ postfix.aliases_file }}: file.managed: - source: salt://postfix/files/aliases @@ -74,7 +74,41 @@ run-newaliases: - cwd: / - watch: - file: {{ postfix.aliases_file }} -{% endif %} +{%- endif %} + +{%- macro postmap_file(filename, mode=644) %} +{%- set file_path = '/etc/postfix/' ~ filename %} +postmap_{{ filename }}: + file.managed: + - name: {{ file_path }} + - source: salt://postfix/files/{{ filename }} + - user: root + - group: root + - mode: {{ mode }} + - template: jinja + - require: + - pkg: postfix + cmd.wait: + - name: /usr/sbin/postmap {{ file_path }} + - cwd: / + - watch: + - file: {{ file_path }} +{%- endmacro %} + +# manage /etc/postfix/virtual if data found in pillar +{%- if 'virtual' in pillar.get('postfix', '') %} +{{ postmap_file('virtual') }} +{%- endif %} + +# manage /etc/postfix/smtp_auth if data found in pillar +{%- if 'smtp_auth' in pillar.get('postfix', '') %} +{{ postmap_file('smtp_auth', 600) }} +{%- endif %} + +# manage /etc/postfix/sender_canonical if data found in pillar +{%- if 'sender_canonical' in pillar.get('postfix', '') %} +{{ postmap_file('sender_canonical') }} +{%- endif %} /etc/postfix/main.cf: file.managed: @@ -88,6 +122,15 @@ run-newaliases: - cmd: postfix.pem {% if 'aliases' in pillar.get('postfix', '') %} - file: {{ postfix.aliases_file }} +{% endif %} +{% if 'virtual' in pillar.get('postfix', '') %} + - file: postmap_virtual +{% endif %} +{% if 'smtp_auth' in pillar.get('postfix', '') %} + - file: postmap_smtp_auth +{% endif %} +{% if 'sender_canonical' in pillar.get('postfix', '') %} + - file: postmap_sender_canonical {% endif %} - watch_in: - service: postfix diff --git a/postfix/files/main.cf b/postfix/files/main.cf index 4b00a95..f2fd2e0 100644 --- a/postfix/files/main.cf +++ b/postfix/files/main.cf @@ -118,7 +118,7 @@ policy-spf_time_limit = {{ policyd_spf.get('time_limit', '3600s') }} virtual_alias_maps = hash:/etc/postfix/virtual {% endif -%} -{% if 'sasl_passwd' in pillar.get('postfix','') %} +{% if 'smtp_auth' in pillar.get('postfix','') %} smtp_sasl_password_maps = hash:/etc/postfix/smtp_auth {% endif %} diff --git a/postfix/files/smtp_auth b/postfix/files/smtp_auth new file mode 100644 index 0000000..215c1e4 --- /dev/null +++ b/postfix/files/smtp_auth @@ -0,0 +1,14 @@ +# Managed by config management +# Don't change it manually +# + +{% set canonical = salt['pillar.get']('postfix:smtp_auth',{}) -%} +{% if canonical is iterable -%} +{%- for entry in salt['pillar.get']('postfix:smtp_auth', []) -%} +{%- for key,value in entry.iteritems() -%} +{{ key }} {{ value }} +{% endfor -%} +{%- endfor -%} +{% endif %} + +# vim: syntax=conf ts=8 -- 2.39.5