homelab/roles/mail/tasks/main.yml

71 lines
2 KiB
YAML

---
- name: Create mail network
become: true
community.docker.docker_network:
name: mail
- name: Create maddy volume
become: true
community.docker.docker_volume:
name: maddy
- name: Copy maddy config
become: true
ansible.builtin.template:
src: maddy.conf.j2
dest: /var/lib/docker/volumes/maddy/_data/maddy.conf
register: maddy_conf
- name: Run maddy
become: true
community.docker.docker_container:
name: maddy
image: foxcpp/maddy:0.7.1
networks:
- name: mail
env:
MADDY_HOSTNAME: mail.comfycamp.space
MADDY_DOMAIN: comfycamp.space
ports:
- 25:25
- 143:143
- 465:465
- 587:587
- 993:993
volumes:
- maddy:/data
- /etc/letsencrypt/live/comfycamp.space/fullchain.pem:/etc/tls/fullchain.pem:ro
- /etc/letsencrypt/live/comfycamp.space/privkey.pem:/etc/tls/privkey.pem:ro
recreate: "{{ maddy_conf.changed }}"
- name: Get users
become: true
community.docker.docker_container_exec:
container: maddy
argv: ["maddy", "creds", "list"]
register: maddy_users
- name: Create users
become: true
community.docker.docker_container_exec:
container: maddy
argv: ["sh", "-c", "echo '{{ item.value }}' | maddy creds create {{ item.key }}"]
when: not item.key in maddy_users.stdout
no_log: True
loop: "{{ users | dict2items }}"
- name: Update passwords
become: true
community.docker.docker_container_exec:
container: maddy
argv: ["sh", "-c", "echo '{{ item.value }}' | maddy creds password {{ item.key }}"]
no_log: True
loop: "{{ users | dict2items }}"
- name: Get imap accounts
become: true
community.docker.docker_container_exec:
container: maddy
argv: ["maddy", "imap-acct", "list"]
register: maddy_imap_accounts
- name: Create imap accounts
become: true
community.docker.docker_container_exec:
container: maddy
argv: ["maddy", "imap-acct", "create", "{{ item.key }}"]
when: not item.key in maddy_imap_accounts.stdout
no_log: True
loop: "{{ users | dict2items }}"