Add option to manage mail aliases using alias states.

This commit is contained in:
Heinz Wiesinger 2017-05-08 16:43:47 +02:00
parent 21fc78dcf7
commit e290d36699
3 changed files with 30 additions and 1 deletions

View File

@ -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: |

View File

@ -1,3 +1,3 @@
# Managed by config management
# See man 5 aliases for format
{{pillar['postfix']['aliases']}}
{{pillar['postfix']['aliases']['content']}}

View File

@ -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