Files @ 3722152897ec
Branch filter:

Location: majic-ansible-roles/roles/mail_server/tasks/main.yml - annotation

branko
MAR-218: Disable Ansible lints for prefixed role variable names:

- At this point in time, it does not make much sense to introduce
prefixing and breaking every single role invocation.
- Might be worth revisting down the line, although it would require
understanding a bit more clearly if prefixing has any kind of
special logic handling or it's pure guidelines.
82951ff4f9f9
82951ff4f9f9
07956dae35fc
23200e1ae9a8
23200e1ae9a8
b0c92677ba93
07956dae35fc
0ad9410c243a
23200e1ae9a8
a20ca43cd967
a20ca43cd967
a20ca43cd967
a20ca43cd967
a20ca43cd967
b0c92677ba93
0ad9410c243a
0ad9410c243a
23200e1ae9a8
a20ca43cd967
a20ca43cd967
a20ca43cd967
b0c92677ba93
61e6cfb81789
61e6cfb81789
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
b0c92677ba93
0ad9410c243a
284ed92d40bb
23200e1ae9a8
23200e1ae9a8
b0c92677ba93
23200e1ae9a8
284ed92d40bb
284ed92d40bb
23200e1ae9a8
23200e1ae9a8
b0c92677ba93
23200e1ae9a8
284ed92d40bb
96e9f230a669
277c561f3f52
277c561f3f52
277c561f3f52
277c561f3f52
277c561f3f52
277c561f3f52
0ad9410c243a
0ad9410c243a
96e9f230a669
96e9f230a669
277c561f3f52
277c561f3f52
277c561f3f52
277c561f3f52
277c561f3f52
277c561f3f52
0ad9410c243a
0ad9410c243a
96e9f230a669
af834be42e8e
a7cd31c6886d
a7cd31c6886d
a7cd31c6886d
a7cd31c6886d
a7cd31c6886d
a7cd31c6886d
a7cd31c6886d
a7cd31c6886d
a7cd31c6886d
96e9f230a669
277c561f3f52
277c561f3f52
277c561f3f52
277c561f3f52
277c561f3f52
277c561f3f52
96e9f230a669
0ad9410c243a
96e9f230a669
96e9f230a669
277c561f3f52
277c561f3f52
277c561f3f52
277c561f3f52
277c561f3f52
277c561f3f52
96e9f230a669
96e9f230a669
96e9f230a669
069c78425a29
069c78425a29
069c78425a29
069c78425a29
069c78425a29
069c78425a29
069c78425a29
069c78425a29
069c78425a29
069c78425a29
aa2802e42d9d
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
aa2802e42d9d
aa2802e42d9d
aa2802e42d9d
aa2802e42d9d
82951ff4f9f9
23200e1ae9a8
23200e1ae9a8
b0c92677ba93
82951ff4f9f9
12abf97ac229
23200e1ae9a8
23200e1ae9a8
b0c92677ba93
12abf97ac229
2f0d3abc3c49
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
12abf97ac229
12abf97ac229
12abf97ac229
12abf97ac229
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
12abf97ac229
12abf97ac229
12abf97ac229
07956dae35fc
07956dae35fc
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
07956dae35fc
12abf97ac229
12abf97ac229
1b05bae8e440
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
1b05bae8e440
1b05bae8e440
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
0004ec73b902
0004ec73b902
107417b217e0
bf96a77e88ab
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
bf96a77e88ab
bf96a77e88ab
bf96a77e88ab
f7579be2c24b
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
f7579be2c24b
f7579be2c24b
f7579be2c24b
f7579be2c24b
107417b217e0
107417b217e0
f7579be2c24b
107417b217e0
277c561f3f52
277c561f3f52
277c561f3f52
277c561f3f52
277c561f3f52
277c561f3f52
107417b217e0
107417b217e0
ce1b1a242584
3bd270c9e860
3bd270c9e860
3bd270c9e860
3bd270c9e860
3bd270c9e860
3bd270c9e860
3bd270c9e860
3bd270c9e860
3bd270c9e860
3bd270c9e860
ce1b1a242584
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
ce1b1a242584
ce1b1a242584
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
107417b217e0
107417b217e0
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
107417b217e0
107417b217e0
107417b217e0
107417b217e0
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
107417b217e0
107417b217e0
107417b217e0
107417b217e0
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
107417b217e0
107417b217e0
107417b217e0
a9e97d3e2306
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
107417b217e0
107417b217e0
107417b217e0
aa7b596ef595
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
aa7b596ef595
5a15eda01800
97be416e882e
e925a89aff82
e925a89aff82
5a15eda01800
97be416e882e
97be416e882e
97be416e882e
23200e1ae9a8
97be416e882e
97be416e882e
97be416e882e
23200e1ae9a8
663c02da41b8
663c02da41b8
663c02da41b8
5a15eda01800
aa7b596ef595
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
aa7b596ef595
a561d73e3242
a561d73e3242
a561d73e3242
12abf97ac229
663c02da41b8
663c02da41b8
663c02da41b8
663c02da41b8
663c02da41b8
663c02da41b8
aa7b596ef595
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
aa7b596ef595
107417b217e0
aa7b596ef595
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
aa7b596ef595
eb9a1b525c77
eb9a1b525c77
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
23200e1ae9a8
eb9a1b525c77
f05039c7d383
7387caca37f3
7387caca37f3
3802c52995e5
9f0f315631e4
7387caca37f3
7387caca37f3
---

- name: Install rsync
  apt:
    name: rsync
    state: present

- name: Install Dovecot packages
  apt:
    name:
      - dovecot-imapd
      - dovecot-ldap
      - dovecot-sieve
      - dovecot-managesieved
    state: present

- name: Install Postfix packages
  apt:
    name:
      - postfix
      - postfix-ldap
    state: present

- name: Purge Exim configuration
  apt:
    name: "exim4*"
    state: absent
    purge: true

- name: Allow Postfix user to traverse the directory with TLS private keys
  user:
    name: postfix
    append: true
    groups: ssl-cert

- name: Allow Dovecot user to traverse the directory with TLS private keys
  user:
    name: dovecot
    append: true
    groups: ssl-cert

- name: Deploy SMTP TLS private key
  copy:
    dest: "/etc/ssl/private/{{ ansible_fqdn }}_smtp.key"
    content: "{{ smtp_tls_key }}"
    mode: 0640
    owner: root
    group: root
  notify:
    - Restart Postfix

- name: Deploy SMTP TLS certificate
  copy:
    dest: "/etc/ssl/certs/{{ ansible_fqdn }}_smtp.pem"
    content: "{{ smtp_tls_certificate }}"
    mode: 0644
    owner: root
    group: root
  notify:
    - Restart Postfix

- name: Generate the SMTP server Diffie-Hellman parameter
  openssl_dhparam:
    owner: root
    group: root
    mode: 0640
    path: "/etc/ssl/private/{{ ansible_fqdn }}_smtp.dh.pem"
    size: 2048
  notify:
    - Restart Postfix

- name: Deploy IMAP TLS private key
  copy:
    dest: "/etc/ssl/private/{{ ansible_fqdn }}_imap.key"
    content: "{{ imap_tls_key }}"
    mode: 0640
    owner: root
    group: root
  notify:
    - Restart Dovecot

- name: Deploy IMAP TLS certificate
  copy:
    dest: "/etc/ssl/certs/{{ ansible_fqdn }}_imap.pem"
    content: "{{ imap_tls_certificate }}"
    mode: 0644
    owner: root
    group: root
  notify:
    - Restart Dovecot

- name: Generate the IMAP server Diffie-Hellman parameter
  openssl_dhparam:
    owner: root
    group: root
    mode: 0640
    path: "/etc/ssl/private/{{ ansible_fqdn }}_imap.dh.pem"
    size: 2048
  notify:
    - Restart Dovecot

- name: Deploy configuration files for checking certificate validity via cron
  copy:
    content: "/etc/ssl/certs/{{ ansible_fqdn }}_{{ item }}.pem"
    dest: "/etc/check_certificate/{{ ansible_fqdn }}_{{ item }}.conf"
    owner: root
    group: root
    mode: 0644
  with_items:
    - smtp
    - imap

- name: Install SWAKS
  apt:
    name: swaks
    state: present

- name: Install milter packages
  apt:
    name: clamav-milter
    state: present

- name: Configure ClamAV Milter
  copy:
    dest: "/etc/clamav/clamav-milter.conf"
    src: "clamav-milter.conf"
    mode: 0644
    owner: root
    group: root
  notify:
    - Restart ClamAV Milter

- name: Set-up privileges for directories within Postfix chroot
  file:
    dest: "{{ item }}"
    mode: 0755
    state: directory
    owner: root
    group: root
  with_items:
    - /var/spool/postfix/var
    - /var/spool/postfix/var/run

- name: Set-up privileges for directories within Postfix chroot
  file:
    dest: "{{ item }}"
    state: directory
    owner: clamav
    group: clamav
    mode: 0755
  with_items:
    - /var/spool/postfix/var/run/clamav

- name: Deploy the LDAP TLS truststore in default location
  copy:
    content: "{{ mail_ldap_tls_truststore }}"
    dest: "/etc/ssl/certs/mail_ldap_tls_truststore.pem"
    owner: root
    group: root
    mode: 0644

- name: Deploy the LDAP TLS truststore in Postfix chroot
  copy:
    content: "{{ mail_ldap_tls_truststore }}"
    dest: "/var/spool/postfix/etc/ssl/certs/mail_ldap_tls_truststore.pem"
    owner: root
    group: root
    mode: 0644
  notify:
    - Restart Postfix

- name: Configure visible mail name of the system
  copy:
    content: "{{ inventory_hostname }}"
    dest: "/etc/mailname"
    owner: root
    group: root
    mode: 0644
  notify:
    - Restart Postfix

- name: Deploy Postfix configurations files for LDAP look-ups
  template:
    src: "{{ item }}.cf.j2"
    dest: "/etc/postfix/{{ item }}.cf"
    owner: root
    group: postfix
    mode: 0640
  with_items:
    - ldap-virtual-alias-maps
    - ldap-virtual-mailbox-domains
    - ldap-virtual-mailbox-maps
  notify:
    - Restart Postfix

- name: Deploy Postfix main configuration
  template:
    src: "main.cf.j2"
    dest: "/etc/postfix/main.cf"
    owner: root
    group: root
    mode: 0644
  notify:
    - Restart Postfix

- name: Set-up local mail aliases
  lineinfile:
    dest: "/etc/aliases"
    line: "{{ item.key }}: {{ item.value }}"
    regexp: "^{{ item.key }}"
    state: present
  with_dict: "{{ local_mail_aliases }}"
  notify:
    - Rebuild mail aliases

- name: Create mail owner group
  group:
    name: "{{ mail_user }}"
    gid: "{{ mail_user_gid | default(omit) }}"
    state: present

- name: Create mail owner user
  user:
    name: "{{ mail_user }}"
    uid: "{{ mail_user_uid | default(omit) }}"
    group: "{{ mail_user }}"
    home: "/var/{{ mail_user }}"
    state: present

- name: Disable Dovecot system authentication
  lineinfile:
    dest: "/etc/dovecot/conf.d/10-auth.conf"
    line: "!include auth-system.conf.ext"
    state: absent
  notify:
    - Restart Dovecot

- name: Deploy Dovecot configuration file with overrides
  template:
    src: "99-local.conf.j2"
    dest: "/etc/dovecot/conf.d/99-local.conf"
    owner: root
    group: root
    mode: 0644
  notify:
    - Restart Dovecot

- name: Deploy Dovecot configuration file for LDAP look-ups
  template:
    src: "dovecot-ldap.conf.ext.j2"
    dest: "/etc/dovecot/dovecot-ldap.conf.ext"
    owner: root
    group: root
    mode: 0600
  notify:
    - Restart Dovecot

- name: Deploy Postifx master process configuration
  template:
    src: "master.cf.j2"
    dest: "/etc/postfix/master.cf"
    owner: root
    group: root
    mode: 0644
  notify:
    - Restart Postfix

- name: Enable and start ClamAV database update service (freshclam)
  service:
    name: clamav-freshclam
    state: started
    enabled: true

- name: Check availability of ClamAV database files
  stat:
    path: "{{ item }}"
  with_items:
    - /var/lib/clamav/bytecode.cld
    - /var/lib/clamav/daily.cld
    - /var/lib/clamav/main.cld
  register: clamav_db_files

- name: Wait for ClamAV database to be available (up to 10 minutes)
  when: not item.stat.exists
  with_items: "{{ clamav_db_files.results }}"
  wait_for:
    path: "{{ item.item | replace('.cld', '.cvd') }}"
    timeout: 600

- name: Enable and start ClamAV daemon and milter services
  service:
    name: "{{ item }}"
    state: started
    enabled: true
  with_items:
    - clamav-daemon
    - clamav-milter

# It may take ClamAV a while to read all the necessary database files etc.
- name: Wait for ClamAV to become available (up to 5 minutes)
  wait_for:
    path: "/var/run/clamav/clamd.ctl"
    timeout: 300

- name: Enable and start Postfix service
  service:
    name: postfix
    state: started
    enabled: true

- name: Enable and start Dovecot service
  service:
    name: dovecot
    state: started
    enabled: true

- name: Deploy firewall configuration for mail server
  copy:
    src: "ferm_mail.conf"
    dest: "/etc/ferm/conf.d/20-mail.conf"
    owner: root
    group: root
    mode: 0640
  notify:
    - Restart ferm

- name: Explicitly run all handlers
  include_tasks: ../handlers/main.yml
  when: "run_handlers | default(False) | bool()"
  tags:
    - handlers