forked from saltstack-formulas/postfix-formula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.sls
155 lines (144 loc) · 4.82 KB
/
config.sls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
{% from "postfix/map.jinja" import postfix with context %}
include:
- postfix
postfix-config-file-directory-config-path:
file.directory:
- name: {{ postfix.config_path }}
- user: root
- group: {{ postfix.root_grp }}
- dir_mode: '0755'
- file_mode: '0644'
- makedirs: True
postfix-config-file-managed-main.cf:
file.managed:
- name: {{ postfix.config_path }}/main.cf
- source: salt://postfix/files/main.cf
- user: root
- group: {{ postfix.root_grp }}
- mode: '0644'
- require:
- pkg: postfix-init-pkg-installed-postfix
- watch_in:
- service: postfix-init-service-running-postfix
- template: jinja
- context:
postfix: {{ postfix|tojson }}
{% if 'vmail' in pillar.get('postfix', '') %}
postfix-config-file-managed-virtual-alias-maps.cf:
file.managed:
- name: {{ postfix.config_path }}/virtual_alias_maps.cf
- source: salt://postfix/files/virtual_alias_maps.cf
- user: root
- group: postfix
- mode: '0640'
- require:
- pkg: postfix-init-pkg-installed-postfix
- watch_in:
- service: postfix-init-service-running-postfix
- template: jinja
postfix-config-file-managed-virtual-mailbox-domains.cf:
file.managed:
- name: {{ postfix.config_path }}/virtual_mailbox_domains.cf
- source: salt://postfix/files/virtual_mailbox_domains.cf
- user: root
- group: postfix
- mode: '0640'
- require:
- pkg: postfix-init-pkg-installed-postfix
- watch_in:
- service: postfix-init-service-running-postfix
- template: jinja
postfix-config-file-managed-virtual-mailbox-maps.cf:
file.managed:
- name: {{ postfix.config_path }}/virtual_mailbox_maps.cf
- source: salt://postfix/files/virtual_mailbox_maps.cf
- user: root
- group: postfix
- mode: '0640'
- require:
- pkg: postfix-init-pkg-installed-postfix
- watch_in:
- service: postfix-init-service-running-postfix
- template: jinja
{% endif %}
{% if salt['pillar.get']('postfix:manage_master_config', True) %}
{% import_yaml "postfix/services.yaml" as postfix_master_services %}
postfix-config-file-managed-master.cf:
file.managed:
- name: {{ postfix.config_path }}/master.cf
- source: salt://postfix/files/master.cf
- user: root
- group: {{ postfix.root_grp }}
- mode: '0644'
- require:
- pkg: postfix-init-pkg-installed-postfix
- watch_in:
- service: postfix-init-service-running-postfix
- template: jinja
- context:
postfix: {{ postfix|tojson }}
postfix_master_services: {{ postfix_master_services|tojson }}
{% endif %}
{%- for domain in salt['pillar.get']('postfix:certificates', {}).keys() %}
postfix-config-file-managed-{{ domain }}-ssl-certificate:
file.managed:
- name: {{ postfix.config_path }}/ssl/{{ domain }}.crt
- makedirs: True
- contents_pillar: postfix:certificates:{{ domain }}:public_cert
- watch_in:
- service: postfix-init-service-running-postfix
postfix-config-file-managed-{{ domain }}-ssl-key:
file.managed:
- name: {{ postfix.config_path }}/ssl/{{ domain }}.key
- mode: '0600'
- makedirs: True
- contents_pillar: postfix:certificates:{{ domain }}:private_key
- watch_in:
- service: postfix-init-service-running-postfix
{% endfor %}
# 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 file_path.startswith('proxy:') %}
{#- Discard the proxy:-prefix #}
{%- set _, file_type, file_path = file_path.split(':') %}
{%- elif ':' in file_path %}
{%- set file_type, file_path = file_path.split(':') %}
{%- else %}
{%- set file_type = default_database_type %}
{%- endif %}
{%- if not file_path.startswith('/') %}
{%- set file_path = postfix.config_path ~ '/' ~ file_path %}
{%- endif %}
{%- if file_type in ("btree", "cdb", "cidr", "dbm", "hash", "pcre", "regexp", "sdbm") %}
{%- set need_postmap = True %}
{%- endif %}
postfix-config-file-managed-{{ mapping }}:
file.managed:
- name: {{ file_path }}
- source: salt://postfix/files/mapping.j2
- user: root
- group: {{ postfix.root_grp }}
{%- if mapping.endswith('_sasl_password_maps') %}
- mode: '0600'
{%- else %}
- mode: '0644'
{%- endif %}
- template: jinja
- context:
data: {{ data|json() }}
- require:
- pkg: postfix-init-pkg-installed-postfix
- file: postfix-config-file-managed-main.cf
{%- if need_postmap %}
postfix-config-cmd-wait-{{ mapping }}:
cmd.wait:
- name: {{ postfix.xbin_prefix }}/sbin/postmap {{ file_path }}
- cwd: /
- watch:
- file: postfix-config-file-managed-{{ mapping }}
- watch_in:
- service: postfix-init-service-running-postfix
{%- endif %}
{% endfor %}