ansible/roles/postfix/tasks/main.yml

146 lines
3.5 KiB
YAML
Raw Permalink Normal View History

---
- name: Install Postfix
2024-09-17 11:50:09 -05:00
ansible.builtin.package:
name: postfix
state: present
notify:
- Restart Postfix
- name: Create /usr/local/etc/mail
2024-09-17 11:50:09 -05:00
ansible.builtin.file:
path: /usr/local/etc/mail
state: directory
owner: root
group: wheel
2024-09-17 11:50:09 -05:00
mode: '0755'
- name: Install Postfix mailer.conf
2024-09-17 11:50:09 -05:00
ansible.builtin.copy:
dest: /usr/local/etc/mail/mailer.conf
src: /usr/local/share/postfix/mailer.conf.postfix
2024-09-17 11:50:09 -05:00
remote_src: true
owner: root
group: wheel
2024-09-17 11:50:09 -05:00
mode: '0644'
- name: Disable sendmail
sysrc:
name: sendmail_enable
value: NONE
- name: Make sure sendmail is stopped
2024-09-17 11:50:09 -05:00
ansible.builtin.service:
name: sendmail
state: stopped
2024-09-17 12:18:39 -05:00
- name: Disable sendmail periodic tasks
2024-09-17 11:50:09 -05:00
ansible.builtin.lineinfile:
path: /etc/periodic.conf
owner: root
group: wheel
2024-09-17 11:50:09 -05:00
mode: '0444'
regexp: '^{{ item }}='
line: '{{ item }}="NO"'
with_items: '{{ sendmail_periodic }}'
- name: Add /var/log/postfix to fstab
2024-09-17 12:18:39 -05:00
ansible.posix.mount:
path: /var/log/postfix
src: tmpfs
fstype: tmpfs
opts: 'rw,size={{ postfix_log_size }},mode={{ postfix_log_mode }},uid={{ postfix_log_uid }},gid={{ postfix_log_gid }},late'
state: mounted
- name: Create Postfix service directories
2024-09-17 11:50:09 -05:00
ansible.builtin.file:
path: '{{ s6_etc_dir }}/service/{{ item }}'
state: directory
owner: root
group: wheel
2024-09-17 11:50:09 -05:00
mode: '0755'
with_items: '{{ postfix_service_dirs }}'
- name: Generate Postfix service scripts
2024-09-17 11:50:09 -05:00
ansible.builtin.template:
dest: '{{ s6_etc_dir }}/service/{{ item }}'
src: '{{ item }}.j2'
2024-09-17 11:50:09 -05:00
mode: '0555'
owner: root
group: wheel
with_items: '{{ postfix_service_scripts }}'
notify:
- Reload s6-rc
- Restart Postfix
- name: Generate Postfix service configuration
2024-09-17 11:50:09 -05:00
ansible.builtin.copy:
dest: '{{ s6_etc_dir }}/service/{{ item.name }}'
content: '{{ item.content }}'
2024-09-17 11:50:09 -05:00
mode: '0444'
owner: root
group: wheel
loop_control:
2024-09-17 11:50:09 -05:00
label: '{{ item.name }} = {{ item.content }}'
notify:
- Reload s6-rc
- Restart Postfix
with_items: '{{ postfix_service_config }}'
- name: Generate Postfix maps
2024-09-17 11:50:09 -05:00
ansible.builtin.template:
dest: '/usr/local/etc/postfix/{{ item.name }}'
src: '{{ item.name }}.j2'
2024-09-17 11:50:09 -05:00
mode: '0444'
owner: root
group: wheel
with_items: '{{ postfix_maps }}'
notify:
- Rebuild Postfix maps
- Reload Postfix
- name: Configure Postfix
2024-09-17 12:18:39 -05:00
postconf:
name: '{{ item.name }}'
value: '{{ item.value | default(omit) }}'
state: '{{ item.state | default(omit) }}'
with_items: '{{ postfix_config }}'
notify:
- Reload Postfix
- name: Configure Postfix services
2024-09-17 11:50:09 -05:00
ansible.builtin.lineinfile:
path: /usr/local/etc/postfix/master.cf
regexp: '^{{ item.name }} +{{ item.type }}'
value: '{{ item.value }}'
with_items: '{{ postfix_services }}'
notify:
- Restart Postfix
- name: Configure per service overrides
postconf_master:
name: '{{ item.name }}'
value: '{{ item.value | default(omit) }}'
state: '{{ item.state | default(omit) }}'
with_items: '{{ postfix_params }}'
notify:
- Restart Postfix
- name: Flush handlers
2024-09-17 11:50:09 -05:00
ansible.builtin.meta: flush_handlers
- name: Start Postfix
2024-09-17 11:50:09 -05:00
ansible.builtin.command: fdmove -c 2 1 s6-rc -l {{ s6_live_dir }} -u -v 2 change postfix
register: change
changed_when: change.stdout | length > 0
- name: Enable Postfix
2024-09-17 11:50:09 -05:00
ansible.builtin.lineinfile:
path: '{{ s6_etc_dir }}/service/enabled/contents'
regexp: "^postfix$"
line: "postfix"
notify:
- Reload s6-rc
- name: Flush handlers (again)
2024-09-17 11:50:09 -05:00
ansible.builtin.meta: flush_handlers