--- - name: Remove default include path to manage configuration via a single template. ansible.builtin.lineinfile: path: /etc/dovecot/dovecot.conf regexp: '^!include conf.d' line: '#!include conf.d/*.conf' - name: Register Dovecot account database ansible.builtin.file: path: "{{ dovecot_passwd_file }}" state: touch owner: root group: dovecot mode: '0640' changed_when: false - name: Ensure mail_home directory (Dovecot) ansible.builtin.file: name: /srv/mail owner: dovecot group: dovecot state: directory mode: '0770' - name: Ensure local configuration file is included from dovecot.conf ansible.builtin.lineinfile: path: /etc/dovecot/dovecot.conf line: '!include_try local.conf' - name: Configure Dovecot ansible.builtin.template: src: dovecot.conf.j2 dest: /etc/dovecot/local.conf notify: restart dovecot - name: Update UID and GID in imap.passwd ansible.builtin.replace: path: "{{ dovecot_passwd_file }}" regexp: '(.*):(\d+):(\d+)$' replace: '\1:{{ maildir_uid }}:{{ maildir_gid }}' when: force_dovecot_passwd_file_maildir_ids notify: restart dovecot - name: Ensure dovecot service is started and enabled. ansible.builtin.service: name: dovecot state: started enabled: yes