ansible-edda/playbooks/roles/system/mail/tasks/main.yml

81 lines
1.8 KiB
YAML

---
- name: "configure mailname"
ansible.builtin.template:
src: "./mailname.j2"
dest: "/etc/mailname"
mode: 0644
register: system_mail_mailname
- name: "configure mailutils"
ansible.builtin.template:
src: "./mailutils.conf.j2"
dest: "/etc/mailutils.conf"
mode: 0644
- name: "install postfix"
ansible.builtin.apt:
name:
- "postfix"
- "ca-certificates"
- "libsasl2-modules"
- name: "configure aliases"
ansible.builtin.template:
src: "./aliases.j2"
dest: "/etc/aliases"
mode: 0644
register: system_mail_aliases
- name: "update aliases"
ansible.builtin.command:
cmd: "newaliases"
when:
system_mail_aliases.changed
- name: "configure postfix"
ansible.builtin.template:
src: "./postfix/main.cf.j2"
dest: "/etc/postfix/main.cf"
mode: 0644
register: system_mail_postfix_conf
- name: "configure credentials"
ansible.builtin.template:
src: "./postfix/sasl_passwd.j2"
dest: "/etc/postfix/sasl_passwd"
mode: 0600
register: system_mail_postfix_credentials
- name: "create hash database"
ansible.builtin.command:
cmd: "postmap /etc/postfix/sasl_passwd"
when:
system_mail_postfix_credentials.changed
- name: "set hash database permissions"
ansible.builtin.file:
path: "/etc/postfix/sasl_passwd.db"
mode: 0600
- name: "enable postfix"
ansible.builtin.systemd:
name: "postfix"
enabled: true
- name: "start postfix"
ansible.builtin.systemd:
name: "postfix"
state: "started"
register: system_mail_postfix_start
- name: "restart postfix"
ansible.builtin.systemd:
name: "postfix"
state: "restarted"
when:
(system_mail_mailname.changed or
system_mail_aliases.changed or
system_mail_postfix_conf.changed or
system_mail_postfix_credentials.changed) and
not system_mail_postfix_start.changed