<commit_before>- include_role:
    name: service
  # static: yes # see static include issue: https://github.com/ansible/ansible/issues/13485
  vars:
    service_name: dovecot
    service_packages:
      - dovecot-ldap
      - dovecot-imapd
      - rsyslog

- lineinfile: dest=/etc/postfix/main.cf line="virtual_transport = dovecot" state=present
  notify: restart postfix

- blockinfile:
    dest: /etc/postfix/master.cf
    block: |
      dovecot   unix  -       n       n       -       -       pipe
        flags=DRhu user=postman:postman argv=/usr/lib/dovecot/deliver -d ${recipient} -f ${sender}
  notify: restart postfix

- name: create postman group
  group:
    name: postman
    state: present

- name: create postman user
  user:
    name: postman
    state: present
    shell: /dev/null

- name: edit dovecot configuration
  lineinfile:
    dest: /etc/dovecot/conf.d/10-master.conf
    line: '    port = 143'
    insertafter: 'inet_listener imap {'
    state: present
  notify: restart dovecot

- blockinfile:
    dest: /etc/dovecot/conf.d/10-master.conf
    insertafter: 'inet_listener imaps {'
    marker: '#{mark} ANSIBLE BLOCK FOR IMAPS PORT'
    block: |
                  port = 993
                  ssl = yes
  notify: restart dovecot

- blockinfile:
    dest: "/etc/dovecot/conf.d/10-master.conf"
    insertafter: "unix_listener auth-userdb {"
    marker: '#{mark} ANSIBLE BLOCK FOR AUTH USER'
    block: |
        group = postman
        mode = 0664
        user = postman
  notify: restart dovecot

- lineinfile:
    dest: /etc/dovecot/conf.d/10-mail.conf
    line: 'mail_location = maildir:/home/postman/%d/%n'
    regexp: '^mail_location = '
    state: present
  notify: restart dovecot

- lineinfile:
    dest: /etc/dovecot/conf.d/10-mail.conf
    line: 'mail_gid :  postman'
    state: present
  notify: restart dovecot

- lineinfile:
    dest: /etc/dovecot/conf.d/10-mail.conf
    line: 'mail_uid :  postman'
    state: present
  notify: restart dovecot

- lineinfile:
    dest: /etc/dovecot/conf.d/10-auth.conf
    line: "!include auth-system.conf.ext"
    state: absent
  notify: restart dovecot

- lineinfile:
    dest: /etc/dovecot/conf.d/10-auth.conf
    line: "!include auth-ldap.conf.ext"
    state: present
  notify: restart dovecot

- lineinfile:
    dest: /etc/dovecot/conf.d/10-auth.conf
    line: "auth_default_realm :  {{ domain }}"
  notify: restart dovecot

- lineinfile:
    dest: /etc/dovecot/conf.d/10-auth.conf
    line: "auth_mechanisms :  login plain"
  notify: restart dovecot

- name: enable ssl key
  blockinfile:
    dest: /etc/dovecot/conf.d/10-ssl.conf
    block: |
        ssl = yes
        ssl_cert = </etc/dovecot/dovecot.cert
        ssl_key = </etc/dovecot/private/dovecot.key

- name: generate the RSA key
# TODO: reenable openssl_privatekey when moving to ansible 2.3
# openssl_privatekey:
#   path: "/etc/dovecot/private/dovecot.key"
#   size: 2048
#   state: present
#   type: RSA
  shell: "openssl genrsa -out /etc/dovecot/private/dovecot.key 2048"
  args:
    creates: /etc/dovecot/private/dovecot.key
  notify: restart dovecot
<commit_msg>update to new dovecot conf format<commit_after>- include_role:
    name: service
  # static: yes # see static include issue: https://github.com/ansible/ansible/issues/13485
  vars:
    service_name: dovecot
    service_packages:
      - dovecot-ldap
      - dovecot-imapd
      - rsyslog

- lineinfile: dest=/etc/postfix/main.cf line="virtual_transport = dovecot" state=present
  notify: restart postfix

- blockinfile:
    dest: /etc/postfix/master.cf
    block: |
      dovecot   unix  -       n       n       -       -       pipe
        flags=DRhu user=postman:postman argv=/usr/lib/dovecot/deliver -d ${recipient} -f ${sender}
  notify: restart postfix

- name: create postman group
  group:
    name: postman
    state: present

- name: create postman user
  user:
    name: postman
    state: present
    shell: /dev/null

- name: edit dovecot configuration
  lineinfile:
    dest: /etc/dovecot/conf.d/10-master.conf
    line: '    port = 143'
    insertafter: 'inet_listener imap {'
    state: present
  notify: restart dovecot

- blockinfile:
    dest: /etc/dovecot/conf.d/10-master.conf
    insertafter: 'inet_listener imaps {'
    marker: '#{mark} ANSIBLE BLOCK FOR IMAPS PORT'
    block: |
                  port = 993
                  ssl = yes
  notify: restart dovecot

- blockinfile:
    dest: "/etc/dovecot/conf.d/10-master.conf"
    insertafter: "unix_listener auth-userdb {"
    marker: '#{mark} ANSIBLE BLOCK FOR AUTH USER'
    block: |
        group = postman
        mode = 0664
        user = postman
  notify: restart dovecot

- lineinfile:
    dest: /etc/dovecot/conf.d/10-mail.conf
    regexp: "{{ item.regexp }}"
    line: "{{ item.line }}"
    state: present
  with_items:
    - { regexp: '^mail_location = ', line: 'mail_location = maildir:/home/postman/%d/%n' }
    - { regexp: 'mail_gid = ', line: 'mail_gid = postman' }
    - { regexp: 'mail_uid = ', line: 'mail_uid = postman' }
  notify: restart dovecot

- lineinfile:
    dest: /etc/dovecot/conf.d/10-auth.conf
    regexp: "{{ item.regexp }}"
    line: "{{ item.line }}"
    state: "{{ item.state }}"
  with_items:
    - { regexp: None, line: 'mail_location = maildir:/home/postman/%d/%n', state: 'absent'}
    - { regexp: None, line: '!include auth-ldap.conf.ext', state: 'present'}
    - { regexp: 'auth_default_realm =', line: 'auth_default_realm =  {{ domain }}', state: 'present'}
    - { regexp: 'auth_mechanisms =', line: 'auth_mechanisms =  login plain', state: 'present'}
    - { regexp: None, line: '!include auth-ldap.conf.ext', state: 'present'}
  notify: restart dovecot

- name: enable ssl key
  blockinfile:
    dest: /etc/dovecot/conf.d/10-ssl.conf
    block: |
        ssl = yes
        ssl_cert = </etc/dovecot/dovecot.cert
        ssl_key = </etc/dovecot/private/dovecot.key

- name: generate the RSA key
# TODO: reenable openssl_privatekey when moving to ansible 2.3
# openssl_privatekey:
#   path: "/etc/dovecot/private/dovecot.key"
#   size: 2048
#   state: present
#   type: RSA
  shell: "openssl genrsa -out /etc/dovecot/private/dovecot.key 2048"
  args:
    creates: /etc/dovecot/private/dovecot.key
  notify: restart dovecot

{'fraction_non_alphanumeric': 0.12385835603268706, 'fraction_numerical': 0.013459381509373498, 'mean_word_length': 2.608092485549133, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1336915', 'n_tokens_mistral': 2391, 'n_tokens_neox': 2246, 'n_words': 508}