blob: 8191c0d713ec2019b0e8b37bed4a993b5742ae60 (
plain)
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
|
---
- name: install packages
pkgng:
name: "{{ item }}"
state: present
with_items:
- opendkim
- postfix
- dovecot
- dovecot-pigeonhole
- name: group - check vmail group
command: pw groupshow {{ mail.user.name }}
register: pw_cmd
ignore_errors: true
changed_when: false
tags: vmail
- name: group - create vmail group
command: pw groupadd {{ mail.user.name }} -g {{ mail.user.id }}
when: pw_cmd.rc != 0
tags: vmail
- name: user - check vmail user
command: pw usershow {{ mail.user.name }}
register: pw_cmd
ignore_errors: true
changed_when: false
tags: vmail
- name: user - create vmail user
command: >
pw useradd {{ mail.user.name }}
-u {{ mail.user.id }} -g {{ mail.user.name }}
-m -M 0700 -d {{ mail.user.home }}
-s /sbin/nologin
-c "Virtual Mail User"
when: pw_cmd.rc != 0
tags: vmail
#
# OpenDKIM
#
- name: opendkim - create directory
file:
path: /usr/local/etc/mail/dkim
state: directory
tags: opendkim
- name: opendkim - generate domain keys
include_tasks: dkim-genkey.yml domain={{ item }}
with_items: "{{ mail.domains }}"
tags: opendkim
- name: opendkim - generate tables
template:
src: "{{ item }}"
dest: /usr/local/etc/mail/dkim/{{ item | basename | regex_replace('\.j2', '') }}
with_items:
- dkim/KeyTable.j2
- dkim/SigningTable.j2
notify: reload-opendkim
tags: opendkim
- name: opendkim - generate config file
template:
src: opendkim.conf.j2
dest: /usr/local/etc/mail/opendkim.conf
notify: reload-opendkim
tags: opendkim
- name: opendkim - enable and start
command: rcenable milter-opendkim
- name: aliases - forward root mails
lineinfile:
path: /etc/mail/aliases
line: "root: root@{{ mail.domains[0] }}"
insertafter: '#?\s*root:'
notify: update-aliases
- name: postfix - set as mailer/MTA
file:
path: /etc/mail/mailer.conf
src: /etc/mail/mailer.conf.postfix
state: link
force: true
- name: postfix - enable postfix and disable sendmail
blockinfile:
path: /etc/rc.conf
marker: "# {mark} ANSIBLE MANAGED - postfix"
block: |
postfix_enable="YES"
# Completely disable sendmail(8) in favor of Postfix
sendmail_enable="NO"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"
- name: postfix - disable sendmail periodic tasks
blockinfile:
path: /etc/periodic.conf
marker: "# {mark} ANSIBLE MANAGED - postfix"
block: |
# Disable sendmail(8) tasks in favor of Postfix
daily_clean_hoststat_enable="NO"
daily_status_mail_rejects_enable="NO"
daily_status_include_submit_mailq="NO"
daily_submit_queuerun="NO"
|