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