main.yml 3.21 KB
Newer Older
Florian Pritz's avatar
Florian Pritz committed
1
2
3
4
5
---

- name: install postfix
  pacman: name=postfix state=present

6
- name: install template configs
7
  template: src={{ item }}.j2 dest=/etc/postfix/{{ item }} owner=root group=root mode=0644
8
9
10
11
  with_items:
    - main.cf
    - master.cf
    - transport
12
    - transport.pcre
13
    - aliases
14
    - users.pcre
15
  notify:
16
    - restart postfix
17
    - postmap additional files
18
    - update aliases db
Florian Pritz's avatar
Florian Pritz committed
19

20
- name: install additional files
21
  copy: src={{ item }} dest=/etc/postfix/{{ item }} owner=root group=root mode=0644
22
23
24
  with_items:
    - access_client
    - access_sender
25
    - access_sender-post-filter
26
    - access_helo
27
    - access_recipient
28
29
30
    - body_checks
    - header_checks
    - relocated
31
32
    - domains
    - mailman_compat
33
    - msa_header_checks
34
35
  notify:
    - postmap additional files
36

Florian Pritz's avatar
Florian Pritz committed
37
38
- name: create dhparam 2048
  command: openssl dhparam -out /etc/postfix/dh2048.pem 2048 creates=/etc/postfix/dh2048.pem
Florian Pritz's avatar
Florian Pritz committed
39
  notify:
Florian Pritz's avatar
Florian Pritz committed
40
41
42
43
    - reload postfix

- name: create dhparam 512
  command: openssl dhparam -out /etc/postfix/dh_512.pem 512 creates=/etc/postfix/dh_512.pem
Florian Pritz's avatar
Florian Pritz committed
44
  notify:
Florian Pritz's avatar
Florian Pritz committed
45
46
    - reload postfix

47
48
49
50
- name: install postfix cert renewal hook
  template: src=letsencrypt.hook.d.j2 dest=/etc/letsencrypt/hook.d/postfix owner=root group=root mode=0755
  when: postfix_smtpd_public

51
- name: install bouncehandler config
52
  template: src=wiki-bouncehandler.conf.j2 dest={{ postfix_wiki_bounce_config }} owner={{ postfix_wiki_bounce_user }} group=root mode=0600
53
54
55
56
57
58
59
  when: postfix_server

- name: install packages for bounce handler
  pacman: name=perl-mediawiki-api,perl-config-simple state=present
  when: postfix_server

- name: install bouncehandler script
60
  copy: src=bouncehandler.pl dest={{ postfix_wiki_bounce_mail_handler }} owner=root group=root mode=0755
61
62
63
  when: postfix_server

- name: make bouncehandler user
64
  user: name={{ postfix_wiki_bounce_user }} shell=/bin/false skeleton=/var/empty state={{ "present" if postfix_server else "absent" }}
65

Florian Pritz's avatar
Florian Pritz committed
66
- name: start and enable postfix
Florian Pritz's avatar
Florian Pritz committed
67
  service: name=postfix enabled=yes state=started
Florian Pritz's avatar
Florian Pritz committed
68
69

- name: remove old files
70
  file: path={{ item }} state=absent
Florian Pritz's avatar
Florian Pritz committed
71
72
73
  with_items:
    - compat_maps
    - compat_maps.db
74

75
- name: install extra packages for relaying via smarthost
76
  when: postfix_relayhost | length > 0
77
78
79
80
81
  package:
    name: cyrus-sasl
    state: present

- name: install relay_passwords file
82
  when: postfix_relayhost | length > 0
83
84
85
86
87
88
89
90
91
  template:
    src: relay_passwords.j2
    dest: /etc/postfix/relay_passwords
    mode: 0640
    owner: root
    group: postfix
  notify:
    - postmap relay_passwords

92
93
- name: create user account on mail to relay with
  delegate_to: mail.archlinux.org
94
  when: postfix_relayhost | length > 0
95
  user:
96
97
    name: "{{ inventory_hostname_short }}"
    comment: "SMTP Relay Account for {{ inventory_hostname }}"
98
    group: nobody
99
    password: "{{ postfix_relay_password | password_hash('sha512') }}"
100
    shell: /sbin/nologin
101
    update_password: always
Kristian Klausen's avatar
Kristian Klausen committed
102
103
    home: /home/"{{ inventory_hostname }}"  # Set home directory so shadow.service does not fail
    create_home: true
104

105
- name: open firewall holes
106
  ansible.posix.firewalld: service={{ item }} permanent=true state=enabled immediate=yes
107
108
109
  with_items:
    - smtp
    - smtp-submission
110
    - smtps
111
  when: postfix_smtpd_public and configure_firewall
112
113
  tags:
    - firewall