/home/travis/.ansible/roles/robertdebock.dovecot/tasks/main.yml
---
# tasks file for dovecot
- name: include assert.yml
  include_tasks: assert.yml
  run_once: yes

- name: install dovecot
  package:
    name: "{{ dovecot_packages }}"
    state: present
  notify:
    - copy sample configuration

- name: flush handlers
  meta: flush_handlers

- name: configure mail_location
  lineinfile:
    path: /etc/dovecot/conf.d/10-mail.conf
    regexp: "^mail_location"
    line: "mail_location = {{ dovecot_mailbox_location }}"
    mode: "0640"

- name: configure mail_access_groups
  lineinfile:
    path: /etc/dovecot/conf.d/10-mail.conf
    regexp: "^mail_access_groups"
    line: "mail_access_groups = {{ dovecot_mail_access_groups }}"
    mode: "0640"

- name: find users in /var/spool/mail
  find:
    path: /var/spool/mail
  register: dovecot_find_users

- name: set permission in /var/spool/mail
  file:
    path: "{{ item.path }}"
    mode: "0600"
  loop: "{{ dovecot_find_users.files }}"
  loop_control:
    label: "{{ item.path | basename }}"

- name: start and enable dovecot
  service:
    name: "{{ dovecot_service }}"
    state: started
    enabled: yes