diff --git a/library/roles/dovecot/defaults/main.yml b/library/roles/dovecot/defaults/main.yml new file mode 100644 index 00000000..9fd290a4 --- /dev/null +++ b/library/roles/dovecot/defaults/main.yml @@ -0,0 +1,19 @@ +--- +dovecot_service_enabled: True +dovecot_rh_pkgs: + - dovecot + - dovecot-pigeonhole + +dovecot_firewalld_services: + - { service: 'pop3', state: 'enabled', zone: '{{ firewalld_default_zone }}' } + - { service: 'pop3s', state: 'enabled', zone: '{{ firewalld_default_zone }}' } + - { service: 'imap', state: 'enabled', zone: '{{ firewalld_default_zone }}' } + - { service: 'imaps', state: 'enabled', zone: '{{ firewalld_default_zone }}' } + +# 24 is LMTP +# 4190 is ManageSieve +dovecot_firewalld_ports: + - { port: 24, protocol: 'tcp', state: 'disabled', zone: '{{ firewalld_default_zone }}' } + - { port: 4190, protocol: 'tcp', state: 'disabled', zone: '{{ firewalld_default_zone }}' } + + diff --git a/library/roles/dovecot/handlers/main.yml b/library/roles/dovecot/handlers/main.yml new file mode 100644 index 00000000..e69de29b diff --git a/library/roles/dovecot/meta/main.yml b/library/roles/dovecot/meta/main.yml new file mode 100644 index 00000000..e69de29b diff --git a/library/roles/dovecot/tasks/dovecot_firewalld.yml b/library/roles/dovecot/tasks/dovecot_firewalld.yml new file mode 100644 index 00000000..4a191aed --- /dev/null +++ b/library/roles/dovecot/tasks/dovecot_firewalld.yml @@ -0,0 +1,12 @@ +--- +- name: Manage the firewalld rules + block: + - name: Manage the dovecot related services + firewalld: service={{ item.service }} zone={{ item.zone }} permanent={{ item.permanent | default(True) }} state={{ item.state }} immediate=True + with_items: '{{ dovecot_firewalld_services }}' + + - name: Manage the dovecot related tcp/udp ports + firewalld: port={{ item.port }}/{{ item.protocol }} zone={{ item.zone }} permanent={{ item.permanent | default(False) }} state={{ item.state }} immediate=True + with_items: '{{ dovecot_firewalld_ports }}' + + tags: [ 'dovecot', 'firewall', 'firewalld', 'iptables', 'iptables_rules' ] \ No newline at end of file diff --git a/library/roles/dovecot/tasks/dovecot_letsencrypt.yml b/library/roles/dovecot/tasks/dovecot_letsencrypt.yml new file mode 100644 index 00000000..d7a25461 --- /dev/null +++ b/library/roles/dovecot/tasks/dovecot_letsencrypt.yml @@ -0,0 +1,10 @@ +--- +- name: Manage the letsencrypt handler + block: + - name: Create the letsencrypt hooks directory if it is not present + file: dest={{ letsencrypt_acme_services_scripts_dir }} state=directory owner=root group=root mode=0755 + + - name: Install the dovecot letsencrypt hook + template: src=dovecot_letsencrypt_hook.sh.j2 dest={{ letsencrypt_acme_services_scripts_dir }}/dovecot owner=root group=root mode=0750 + + tags: [ 'dovecot', 'imap', 'letsencrypt' ] diff --git a/library/roles/dovecot/tasks/dovecot_rh.yml b/library/roles/dovecot/tasks/dovecot_rh.yml new file mode 100644 index 00000000..5916b705 --- /dev/null +++ b/library/roles/dovecot/tasks/dovecot_rh.yml @@ -0,0 +1,15 @@ +--- +- name: Install the dovecot packages and start the service + block: + - name: Install the dovecot packages + yum: pkg={{ dovecot_rh_pkgs }} + + - name: Ensure that the service is started and enabled + service: name=dovecot state=started enabled=yes + when: dovecot_service_enabled | bool + + - name: Stop and disable the dovecot service + service: name=dovecot state=stopped enabled=no + when: not dovecot_service_enabled | bool + + tags: [ 'dovecot', 'imap' ] diff --git a/library/roles/dovecot/tasks/main.yml b/library/roles/dovecot/tasks/main.yml new file mode 100644 index 00000000..d99368fb --- /dev/null +++ b/library/roles/dovecot/tasks/main.yml @@ -0,0 +1,8 @@ +--- +- import_tasks: dovecot_rh.yml + when: ansible_distribution_file_variety == "RedHat" +- import_tasks: dovecot_firewalld.yml + when: firewalld_enabled is defined and firewalld_enabled | bool +- import_tasks: dovecot_letsencrypt.yml + when: letsencrypt_acme_install is defined and letsencrypt_acme_install | bool + diff --git a/library/roles/dovecot/templates/dovecot_letsencrypt_hook.sh.j2 b/library/roles/dovecot/templates/dovecot_letsencrypt_hook.sh.j2 new file mode 100644 index 00000000..02f0e443 --- /dev/null +++ b/library/roles/dovecot/templates/dovecot_letsencrypt_hook.sh.j2 @@ -0,0 +1,5 @@ +#!/bin/bash + +/bin/systemctl reload dovecot > {{ letsencrypt_acme_sh_log_dir }}/dovecot.log 2>&1 + +exit $? diff --git a/library/roles/dovecot/vars/main.yml b/library/roles/dovecot/vars/main.yml new file mode 100644 index 00000000..e69de29b