ansible-edda/plays/roles/system_mail/tasks/main.yml

81 lines
1.7 KiB
YAML
Raw Normal View History

- name: "configure mailname"
ansible.builtin.template:
src: "./mailname.j2"
dest: "/etc/mailname"
mode: 0644
register: 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: mail_aliases
- name: "update aliases"
ansible.builtin.command:
cmd: "newaliases"
when:
mail_aliases.changed
- name: "configure postfix"
ansible.builtin.template:
src: "./postfix/main.cf.j2"
dest: "/etc/postfix/main.cf"
mode: 0644
register: mail_postfix_conf
- name: "configure credentials"
ansible.builtin.template:
src: "./postfix/sasl_passwd.j2"
dest: "/etc/postfix/sasl_passwd"
mode: 0600
register: mail_postfix_credentials
- name: "create hash database"
ansible.builtin.command:
cmd: "postmap /etc/postfix/sasl_passwd"
when:
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:
mail_postfix_start
- name: "restart postfix"
ansible.builtin.systemd:
name: "postfix"
state: "restarted"
when:
(mail_mailname.changed or
mail_aliases.changed or
mail_postfix_conf.changed or
mail_postfix_credentials.changed) and
not mail_postfix_start.changed