ansible-development-environ.../roles/postfix/tasks/main.yml

133 lines
3.3 KiB
YAML

---
# tasks file for postfix
- name: import assert.yml
ansible.builtin.import_tasks: assert.yml
run_once: yes
delegate_to: localhost
- name: pre-configure debian systems
ansible.builtin.debconf:
name: postfix
question: postfix/main_mailer_type
vtype: string
value: "No configuration"
when:
- ansible_os_family == "Debian"
- name: install postfix
ansible.builtin.package:
name: postfix
state: present
- name: install postfix-mysql
ansible.builtin.package:
name: postfix-mysql
state: present
when:
- (postfix_virtual_mailbox_maps is defined and "'mysql' in postfix_virtual_mailbox_maps) or
(postfix_virtual_mailbox_domains is defined and 'mysql' in postfix_virtual_mailbox_domains) or
(postix_virtual_alias_maps is defined and 'mysql' in postix_virtual_alias_maps")
- name: configure postfix (transport_maps)
ansible.builtin.template:
src: "{{ postfix_transport_maps_template }}"
dest: /etc/postfix/transport
mode: "0644"
notify:
- validate configuration
- rebuild transport_maps database
when:
- postfix_transport_maps_template is defined
- name: configure postfix (header_checks)
ansible.builtin.template:
src: "{{ postfix_header_checks_template }}"
dest: /etc/postfix/header_checks
mode: "0644"
notify:
- validate configuration
- reload postfix
when:
- postfix_header_checks_template is defined
- name: configure postfix (main.cf)
ansible.builtin.template:
src: main.cf.j2
dest: /etc/postfix/main.cf
validate: postconf -d -c %s
mode: "0644"
notify:
- validate configuration
- reload postfix
- name: configure postfix (master.cf)
ansible.builtin.template:
src: master.cf.j2
dest: /etc/postfix/master.cf
validate: postconf -d -c %s
mode: "0644"
notify:
- validate configuration
- restart postfix
- name: flush handlers
ansible.builtin.meta: flush_handlers
- name: configure aliases
ansible.builtin.lineinfile:
path: "{{ postfix_alias_path }}"
regexp: "^{{ item.name }}:"
line: "{{ item.name }}: {{ item.destination }}"
mode: "0644"
when:
- postfix_aliases is defined
loop: "{{ postfix_aliases }}"
notify:
- rebuild alias database
- reload postfix
loop_control:
label: "{{ item.name }}"
- name: configure sender_access
ansible.builtin.lineinfile:
path: "{{ postfix_sender_access_path }}"
regexp: "^{{ item.domain }}"
line: "{{ item.domain }} {{ item.action }}"
create: yes
mode: "0644"
when:
- postfix_sender_access is defined
loop: "{{ postfix_sender_access }}"
notify:
- rebuild sender_access database
- reload postfix
loop_control:
label: "{{ item.domain }}"
- name: configure recipient_access
ansible.builtin.lineinfile:
path: "{{ postfix_recipient_access_path }}"
regexp: "^{{ item.domain }}"
line: "{{ item.domain }} {{ item.action }}"
create: yes
mode: "0644"
when:
- postfix_recipient_access is defined
loop: "{{ postfix_recipient_access }}"
notify:
- validate configuration
- rebuild recipient_access database
- reload postfix
loop_control:
label: "{{ item.domain }}"
- name: flush handlers again
ansible.builtin.meta: flush_handlers
- name: start and enable postfix
ansible.builtin.service:
name: "{{ postfix_service }}"
state: started
enabled: yes