2015-02-26 10:19:08 -05:00
|
|
|
{% from "postfix/map.jinja" import postfix with context %}
|
|
|
|
|
2013-06-13 01:55:32 -04:00
|
|
|
postfix:
|
2015-02-26 10:19:08 -05:00
|
|
|
pkg.installed:
|
2015-08-22 06:46:35 -04:00
|
|
|
- name: {{ postfix.package }}
|
2015-02-26 10:19:08 -05:00
|
|
|
- watch_in:
|
|
|
|
- service: postfix
|
2013-06-13 01:55:32 -04:00
|
|
|
service.running:
|
2016-05-18 13:29:37 -04:00
|
|
|
- enable: {{ salt['pillar.get']('postfix:enable_service', True) }}
|
2013-06-13 01:55:32 -04:00
|
|
|
- require:
|
|
|
|
- pkg: postfix
|
2014-04-23 15:02:09 -04:00
|
|
|
- watch:
|
|
|
|
- pkg: postfix
|
|
|
|
|
2016-12-29 05:51:09 -05:00
|
|
|
{# Used for newaliases, postalias and postconf #}
|
|
|
|
{%- set default_database_type = salt['pillar.get']('postfix:config:default_database_type', 'hash') %}
|
|
|
|
|
2014-04-23 15:02:09 -04:00
|
|
|
# manage /etc/aliases if data found in pillar
|
|
|
|
{% if 'aliases' in pillar.get('postfix', '') %}
|
2017-05-08 10:43:47 -04:00
|
|
|
{% if salt['pillar.get']('postfix:aliases:use_file', true) == true %}
|
2016-12-29 06:22:58 -05:00
|
|
|
{%- set need_newaliases = False %}
|
|
|
|
{%- set file_path = postfix.aliases_file %}
|
|
|
|
{%- if ':' in file_path %}
|
|
|
|
{%- set file_type, file_path = postfix.aliases_file.split(':') %}
|
|
|
|
{%- else %}
|
|
|
|
{%- set file_type = default_database_type %}
|
|
|
|
{%- endif %}
|
|
|
|
{%- if file_type in ("btree", "cdb", "dbm", "hash", "sdbm") %}
|
|
|
|
{%- set need_newaliases = True %}
|
|
|
|
{%- endif %}
|
|
|
|
postfix_alias_database:
|
2014-04-23 15:02:09 -04:00
|
|
|
file.managed:
|
2016-12-29 06:22:58 -05:00
|
|
|
- name: {{ file_path }}
|
2017-08-24 06:49:05 -04:00
|
|
|
- source: salt://postfix/files/mapping.j2
|
2014-04-23 15:02:09 -04:00
|
|
|
- user: root
|
2017-08-24 07:02:46 -04:00
|
|
|
- group: {{ postfix.root_grp }}
|
2014-04-23 15:02:09 -04:00
|
|
|
- mode: 644
|
|
|
|
- template: jinja
|
2017-08-24 06:49:05 -04:00
|
|
|
- context:
|
|
|
|
data: {{ salt['pillar.get']('postfix:aliases:present') }}
|
|
|
|
colon: True
|
2014-04-23 15:02:09 -04:00
|
|
|
- require:
|
|
|
|
- pkg: postfix
|
2016-12-29 06:22:58 -05:00
|
|
|
{%- if need_newaliases %}
|
2014-04-23 15:02:09 -04:00
|
|
|
cmd.wait:
|
|
|
|
- name: newaliases
|
|
|
|
- cwd: /
|
|
|
|
- watch:
|
2016-12-29 06:22:58 -05:00
|
|
|
- file: {{ file_path }}
|
|
|
|
{%- endif %}
|
2017-05-08 10:43:47 -04:00
|
|
|
{% 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 %}
|
2014-04-23 15:02:09 -04:00
|
|
|
{% endif %}
|
|
|
|
|
2016-04-08 11:50:52 -04:00
|
|
|
# manage various mappings
|
|
|
|
{% for mapping, data in salt['pillar.get']('postfix:mapping', {}).items() %}
|
|
|
|
{%- set need_postmap = False %}
|
|
|
|
{%- set file_path = salt['pillar.get']('postfix:config:' ~ mapping) %}
|
|
|
|
{%- if ':' in file_path %}
|
2016-12-29 05:33:44 -05:00
|
|
|
{%- set file_type, file_path = file_path.split(':') %}
|
2016-12-29 05:51:09 -05:00
|
|
|
{%- else %}
|
|
|
|
{%- set file_type = default_database_type %}
|
|
|
|
{%- endif %}
|
2017-08-24 06:52:06 -04:00
|
|
|
{%- if not file_path.startswith('/') %}
|
|
|
|
{%- set file_path = postfix.config_path ~ '/' ~ file_path %}
|
|
|
|
{%- endif %}
|
2016-12-29 05:51:09 -05:00
|
|
|
{%- if file_type in ("btree", "cdb", "dbm", "hash", "sdbm") %}
|
|
|
|
{%- set need_postmap = True %}
|
2016-04-08 11:50:52 -04:00
|
|
|
{%- endif %}
|
|
|
|
postfix_{{ mapping }}:
|
|
|
|
file.managed:
|
|
|
|
- name: {{ file_path }}
|
|
|
|
- source: salt://postfix/files/mapping.j2
|
|
|
|
- user: root
|
2017-08-24 07:02:46 -04:00
|
|
|
- group: {{ postfix.root_grp }}
|
2016-04-08 11:54:09 -04:00
|
|
|
{%- if mapping.endswith('_sasl_password_maps') %}
|
2016-04-08 11:50:52 -04:00
|
|
|
- mode: 600
|
|
|
|
{%- else %}
|
|
|
|
- mode: 644
|
|
|
|
{%- endif %}
|
|
|
|
- template: jinja
|
|
|
|
- context:
|
|
|
|
data: {{ data|json() }}
|
|
|
|
- require:
|
|
|
|
- pkg: postfix
|
|
|
|
{%- if need_postmap %}
|
|
|
|
cmd.wait:
|
2017-08-24 07:02:46 -04:00
|
|
|
- name: {{ postfix.xbin_prefix }}/sbin/postmap {{ file_path }}
|
2016-04-08 11:50:52 -04:00
|
|
|
- cwd: /
|
|
|
|
- watch:
|
|
|
|
- file: {{ file_path }}
|
|
|
|
- watch_in:
|
|
|
|
- service: postfix
|
|
|
|
{%- endif %}
|
|
|
|
{% endfor %}
|