2015-02-26 16:19:08 +01:00
|
|
|
{% from "postfix/map.jinja" import postfix with context %}
|
|
|
|
|
2020-06-07 23:53:00 +02:00
|
|
|
{%- if grains.os_family == "Suse" %}
|
|
|
|
# The existence of this file prevents the system to
|
|
|
|
# overwrite files from salt when installing.
|
2021-03-14 22:33:21 +01:00
|
|
|
postfix-init-file-managed-postfix.configured:
|
2020-06-07 23:53:00 +02:00
|
|
|
file.managed:
|
2021-03-14 22:33:21 +01:00
|
|
|
- name: /var/adm/postfix.configured
|
2020-06-07 23:53:00 +02:00
|
|
|
- contents: ''
|
|
|
|
- mode: '0644'
|
|
|
|
- user: 'root'
|
|
|
|
- group: 'root'
|
|
|
|
- require_in:
|
2021-03-14 22:33:21 +01:00
|
|
|
- pkg: postfix-init-pkg-installed-postfix
|
2020-06-07 23:53:00 +02:00
|
|
|
{%- endif %}
|
|
|
|
|
2021-03-14 22:33:21 +01:00
|
|
|
postfix-init-pkg-installed-postfix:
|
2015-02-26 16:19:08 +01:00
|
|
|
pkg.installed:
|
2015-08-22 12:46:35 +02:00
|
|
|
- name: {{ postfix.package }}
|
2020-06-07 23:53:00 +02:00
|
|
|
{%- if grains.os_family == "FreeBSD" %}
|
2018-07-24 15:38:10 +02:00
|
|
|
- force: True
|
|
|
|
- batch: True
|
|
|
|
{%- endif %}
|
2015-02-26 16:19:08 +01:00
|
|
|
- watch_in:
|
2021-03-14 22:33:21 +01:00
|
|
|
- service: postfix-init-service-running-postfix
|
|
|
|
|
|
|
|
postfix-init-service-running-postfix:
|
2013-06-13 07:55:32 +02:00
|
|
|
service.running:
|
2021-03-14 22:33:21 +01:00
|
|
|
- name: postfix
|
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:
|
2021-03-14 22:33:21 +01:00
|
|
|
- pkg: postfix-init-pkg-installed-postfix
|
2014-04-23 21:02:09 +02:00
|
|
|
- watch:
|
2021-03-14 22:33:21 +01:00
|
|
|
- pkg: postfix-init-pkg-installed-postfix
|
2014-04-23 21:02:09 +02:00
|
|
|
|
2019-07-25 22:15:55 +02:00
|
|
|
{%- if salt['pillar.get']('postfix:reload_service', True) %}
|
|
|
|
# Restart postfix if the package was changed.
|
|
|
|
# This also provides an ID to be used in a watch_in statement.
|
2021-03-14 22:33:21 +01:00
|
|
|
postfix-init-service-running-postfix-restart:
|
2019-07-25 22:15:55 +02:00
|
|
|
service.running:
|
|
|
|
- name: postfix
|
|
|
|
- watch:
|
2021-03-14 22:33:21 +01:00
|
|
|
- pkg: postfix-init-pkg-installed-postfix
|
2019-07-25 22:15:55 +02:00
|
|
|
{%- endif %}
|
|
|
|
|
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 %}
|
2022-01-24 19:09:21 +01:00
|
|
|
{%- set file_type = postfix.default_database_type %}
|
2016-12-29 12:22:58 +01:00
|
|
|
{%- endif %}
|
|
|
|
{%- if file_type in ("btree", "cdb", "dbm", "hash", "sdbm") %}
|
|
|
|
{%- set need_newaliases = True %}
|
|
|
|
{%- endif %}
|
2021-03-14 22:33:21 +01:00
|
|
|
postfix-init-file-managed-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 }}
|
2020-10-02 19:49:13 +02:00
|
|
|
- mode: '0644'
|
2014-04-23 21:02:09 +02:00
|
|
|
- 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:
|
2021-03-14 22:33:21 +01:00
|
|
|
- pkg: postfix-init-pkg-installed-postfix
|
|
|
|
|
2016-12-29 12:22:58 +01:00
|
|
|
{%- if need_newaliases %}
|
2022-02-11 23:49:27 +01:00
|
|
|
postfix-init-cmd-run-new-aliases:
|
|
|
|
cmd.run:
|
2014-04-23 21:02:09 +02:00
|
|
|
- name: newaliases
|
|
|
|
- cwd: /
|
2022-02-11 23:49:27 +01:00
|
|
|
- onchanges:
|
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() %}
|
2021-03-14 22:33:21 +01:00
|
|
|
postfix-init-alias-present-{{ user }}:
|
2017-05-08 16:43:47 +02:00
|
|
|
alias.present:
|
|
|
|
- name: {{ user }}
|
|
|
|
- target: {{ target }}
|
|
|
|
{%- endfor %}
|
|
|
|
{%- for user in salt['pillar.get']('postfix:aliases:absent', {}) %}
|
2021-03-14 22:33:21 +01:00
|
|
|
postfix-init-alias-absent-{{ user }}:
|
2017-05-08 16:43:47 +02:00
|
|
|
alias.absent:
|
|
|
|
- name: {{ user }}
|
|
|
|
{%- endfor %}
|
|
|
|
{% endif %}
|
2014-04-23 21:02:09 +02:00
|
|
|
{% endif %}
|