]> Frank Brehm's Git Trees - salt/states.git/commitdiff
Adding states for postfix mappings
authorFrank Brehm <frank@brehm-online.com>
Mon, 29 Feb 2016 15:00:07 +0000 (16:00 +0100)
committerFrank Brehm <frank@brehm-online.com>
Mon, 29 Feb 2016 15:00:07 +0000 (16:00 +0100)
postfix/common.sls
postfix/files/main.cf
postfix/files/smtp_auth [new file with mode: 0644]

index eed0798018da366b5a27a38f8506f147854b2302..2d881f745af9b3407c2056933494da8adb165a05 100644 (file)
@@ -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
index 4b00a95ecb061fe56aa10f0f8fe58161aa1267a8..f2fd2e03ded2e02fc077244bea2dec89b883ae3a 100644 (file)
@@ -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 (file)
index 0000000..215c1e4
--- /dev/null
@@ -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