From e290d36699455d61c1132dbe48c8d929251e9a83 Mon Sep 17 00:00:00 2001 From: Heinz Wiesinger Date: Mon, 8 May 2017 16:43:47 +0200 Subject: [PATCH] Add option to manage mail aliases using alias states. --- pillar.example | 15 +++++++++++++++ postfix/aliases | 2 +- postfix/init.sls | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/pillar.example b/pillar.example index d83b61c..bb09c3a 100644 --- a/pillar.example +++ b/pillar.example @@ -94,6 +94,21 @@ postfix: hosts: DB_HOST dbname: postfix_db + aliases: + # manage single aliases + # this uses the aliases file defined in the minion config, /etc/aliases by default + use_file: false + present: + root: info@example.com + absent: + - root + + # manage entire aliases file + use_file: true + content: | + # Forward all local *nix users mail to our admins (via greedy regexp) + /.+/ admins@example.com + certificates: server-cert: public_cert: | diff --git a/postfix/aliases b/postfix/aliases index d02055c..04fa424 100644 --- a/postfix/aliases +++ b/postfix/aliases @@ -1,3 +1,3 @@ # Managed by config management # See man 5 aliases for format -{{pillar['postfix']['aliases']}} +{{pillar['postfix']['aliases']['content']}} diff --git a/postfix/init.sls b/postfix/init.sls index fc6d6c2..8d364ee 100644 --- a/postfix/init.sls +++ b/postfix/init.sls @@ -17,6 +17,7 @@ postfix: # manage /etc/aliases if data found in pillar {% if 'aliases' in pillar.get('postfix', '') %} +{% if salt['pillar.get']('postfix:aliases:use_file', true) == true %} {%- set need_newaliases = False %} {%- set file_path = postfix.aliases_file %} {%- if ':' in file_path %} @@ -44,6 +45,19 @@ postfix_alias_database: - watch: - file: {{ file_path }} {%- endif %} +{% else %} + {%- for user, target in salt['pillar.get']('postfix:aliases:present', {}).items() %} +postfix_alias_present_{{ user }}: + alias.present: + - name: {{ user }} + - target: {{ target }} + {%- endfor %} + {%- for user in salt['pillar.get']('postfix:aliases:absent', {}) %} +postfix_alias_absent_{{ user }}: + alias.absent: + - name: {{ user }} + {%- endfor %} +{% endif %} {% endif %} # manage various mappings