From dbd14d1da7826eaebb8bd5cf339de77ee92bec5b Mon Sep 17 00:00:00 2001 From: Janik von Rotz Date: Wed, 11 Dec 2024 13:56:46 +0100 Subject: [PATCH] feat: replace mailhog with mailpit --- README.md | 9 ++-- plays/all.yml | 2 + .../filter_plugins}/odoo_passwd.py | 0 roles/docker_volume/files/docker-volume-copy | 5 +- roles/mailhog/README.md | 2 +- roles/mailpit/README.md | 51 +++++++++++++++++++ roles/mailpit/defaults/main.yml | 6 +++ roles/mailpit/meta/main.yml | 6 +++ roles/mailpit/tasks/mailpit.yml | 30 +++++++++++ roles/mailpit/tasks/main.yml | 4 ++ 10 files changed, 109 insertions(+), 6 deletions(-) rename {filter_plugins => plays/filter_plugins}/odoo_passwd.py (100%) create mode 100644 roles/mailpit/README.md create mode 100644 roles/mailpit/defaults/main.yml create mode 100644 roles/mailpit/meta/main.yml create mode 100644 roles/mailpit/tasks/mailpit.yml create mode 100644 roles/mailpit/tasks/main.yml diff --git a/README.md b/README.md index 241e174f..2dbc1229 100644 --- a/README.md +++ b/README.md @@ -43,10 +43,10 @@ Create an inventory folder and configure a role. Have a look at the Ansible roles and check how to configure them. -| Role | Description | -| -------------------------------------------- | ------------------------------------ | -| [acme_sh](roles/acme_sh/README.md) | Issue & renew the free certificates. | -| [alertmanager](roles/alertmanager/README.md) | Deploy Alertmanager container. | +| Role | Description | +| ---------------------------------------------------------------------- | ---------------------------------------------------------------- | +| [acme_sh](roles/acme_sh/README.md) | Issue & renew the free certificates. | +| [alertmanager](roles/alertmanager/README.md) | Deploy Alertmanager container. | | [ansible_scripts](roles/ansible_scripts/README.md) | Install Ansible scripts. | | [bigbluebutton](roles/bigbluebutton/README.md) | Install BigBlueButton with https and greenlight. | | [bigbluebutton_exporter](roles/bigbluebutton_exporter/README.md) | Deploy BigBlueButton exporter container. | @@ -92,6 +92,7 @@ Have a look at the Ansible roles and check how to configure them. | [logstash](roles/logstash/README.md) | Deploy Logstash Docker container. | | [loki](roles/loki/README.md) | Deploy Loki container. | | [mailhog](roles/mailhog/README.md) | Deploy MailHog Docker container. | +| [mailpit](roles/mailpit/README.md) | Deploy Mailpit Docker container. | | [maintenance](roles/maintenance/README.md) | Maintain operating system and disk space. | | [mariadb](roles/mariadb/README.md) | Deploy MariaDB database container. | | [matomo](roles/matomo/README.md) | Deploy Matomo container. | diff --git a/plays/all.yml b/plays/all.yml index f3cbef0b..72223bd3 100644 --- a/plays/all.yml +++ b/plays/all.yml @@ -82,3 +82,5 @@ tags: meilisync - role: n8n tags: n8n + - role: mailpit + tags: mailpit \ No newline at end of file diff --git a/filter_plugins/odoo_passwd.py b/plays/filter_plugins/odoo_passwd.py similarity index 100% rename from filter_plugins/odoo_passwd.py rename to plays/filter_plugins/odoo_passwd.py diff --git a/roles/docker_volume/files/docker-volume-copy b/roles/docker_volume/files/docker-volume-copy index 81c501a5..d6b935ec 100755 --- a/roles/docker_volume/files/docker-volume-copy +++ b/roles/docker_volume/files/docker-volume-copy @@ -87,4 +87,7 @@ docker container run --rm \ -v "$SOURCE_VOLUME":/from \ -v "$TARGET_VOLUME":/to \ alpine ash -c "cd /to; mkdir -p .$TARGET_PATH; cd /from$SOURCE_PATH; cp -av . /to$TARGET_PATH" \ - > /dev/null && { echo "Docker volume copy has finished."; } \ No newline at end of file + > /dev/null && { echo "Docker volume copy has finished."; } + +echo "Fix ownership for $TARGET_PATH in container:" +echo "docker exec -u root \$CONTAINER chown -R \$USER:\$GROUP /path/to$TARGET_PATH" \ No newline at end of file diff --git a/roles/mailhog/README.md b/roles/mailhog/README.md index eb017ae4..245cc277 100644 --- a/roles/mailhog/README.md +++ b/roles/mailhog/README.md @@ -47,4 +47,4 @@ nginx_proxies: ### Odoo config -To setup a outgoing mailhog connection simply use the hostname `mailogXX` and port `1025`. \ No newline at end of file +To setup a outgoing mailhog connection simply use the hostname `mailhogXX` and port `1025`. \ No newline at end of file diff --git a/roles/mailpit/README.md b/roles/mailpit/README.md new file mode 100644 index 00000000..9ded8412 --- /dev/null +++ b/roles/mailpit/README.md @@ -0,0 +1,51 @@ +# Mailpit role + +Deploy Mailpit container. + +## Usage + +Configure the role. + +```yml +# https://hub.docker.com/r/axllent/mailpit +mailpit_image: axllent/mailpit:latest +mailpit_description: Odoo Mail Catcher # default: Mailpit +mailpit_hostname: mailpit01 +mailpit_data_dir: /usr/share/mailpit_data01 # default: "/usr/share/{{ mailpit_hostname }}" +mailpit_timezone: Europe/Paris # default: Europe/Zurich +mailpit_webroot: /mailpit/ # default: / +mailpit_users: # default: [] + - username: admin + password: "{{ vault_mailpit_user_admin_password }}" +``` + +And include it in your playbook. + +```yml +- hosts: mailpit + roles: + - role: mailpit +``` + +## Docs + +### Nginx config + +Setup this Nginx configuration for the `mailpit01` host: + +```yaml +nginx_proxies: + - src_hostname: www.example.com + dest_hostname: webserver + locations: + - path: /mailpit + dest_hostname: mailpit01 + dest_port: 8025 + options: | + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; +``` + +### Odoo config + +To setup a outgoing mailpit connection simply use the hostname `mailpitXX` and port `1025`. \ No newline at end of file diff --git a/roles/mailpit/defaults/main.yml b/roles/mailpit/defaults/main.yml new file mode 100644 index 00000000..cfa1bb03 --- /dev/null +++ b/roles/mailpit/defaults/main.yml @@ -0,0 +1,6 @@ +--- +mailpit_description: Mailpit +mailpit_data_dir: /usr/share/{{ mailpit_hostname }} +mailpit_users: [] +mailpit_webroot: / +mailpit_timezone: Europe/Zurich \ No newline at end of file diff --git a/roles/mailpit/meta/main.yml b/roles/mailpit/meta/main.yml new file mode 100644 index 00000000..1bd73025 --- /dev/null +++ b/roles/mailpit/meta/main.yml @@ -0,0 +1,6 @@ +--- +dependencies: # noqa 701 + - role: docker_network + tags: + - docker_network + - depends diff --git a/roles/mailpit/tasks/mailpit.yml b/roles/mailpit/tasks/mailpit.yml new file mode 100644 index 00000000..b612f81f --- /dev/null +++ b/roles/mailpit/tasks/mailpit.yml @@ -0,0 +1,30 @@ +--- +- name: Configure user access for {{ role_name }} + community.general.htpasswd: + path: "{{ mailpit_data_dir }}/auth" + name: "{{ item.username }}" + password: "{{ item.password }}" + crypt_scheme: bcrypt + loop: "{{ mailpit_users }}" + +- name: Start {{ role_name }} container {{ mailpit_hostname }} + community.docker.docker_container: + name: "{{ mailpit_hostname }}" + labels: + description: "{{ mailpit_description }}" + image: "{{ mailpit_image }}" + restart_policy: unless-stopped + recreate: false + env: + TZ: "{{ mailpit_timezone }}" + MP_UI_AUTH_FILE: "{{ '/etc/mailpit/auth' if mailpit_users else ''}}" + command: "--webroot {{ mailpit_webroot }}" + volumes: + - "{{ mailpit_data_dir }}/auth:/etc/mailpit/auth" + networks: + - name: "{{ docker_network_name }}" + log_driver: "{{ docker_log_driver }}" + log_options: + max-size: "{{ docker_log_max_size }}" + max-file: "{{ docker_log_max_file }}" + tag: "{{ mailpit_hostname }}|{{ role_name }}" diff --git a/roles/mailpit/tasks/main.yml b/roles/mailpit/tasks/main.yml new file mode 100644 index 00000000..9cbff41e --- /dev/null +++ b/roles/mailpit/tasks/main.yml @@ -0,0 +1,4 @@ +--- +- name: Include {{ role_name }} tasks + ansible.builtin.include_tasks: "{{ role_name }}.yml" + when: mailpit_image is defined