Skip to content

role:postfix: add postfix__recipient_canonicals variable #185

@slalomsk8er

Description

@slalomsk8er

This would allow to send all local mails to a team mailbox and would make the following playbook obsolete.

---
- name: Configure Postfix canonical maps like Exim rewrites
  hosts: Monitoring:&rpm
  become: yes
  vars:
    sender_canonical_file: /etc/postfix/sender_canonical
    recipient_canonical_file: /etc/postfix/recipient_canonical
    public_domain: example.com
    team_mailbox: monitoring_team

  tasks:

    - name: Ensure postfix-pcre package is installed
      package:
        name: postfix-pcre
        state: present
      tags: postfix

    - name: Create sender_canonical map (user@host.domain -> user_host.domain@{{ public_domain }})
      copy:
        dest: "{{ sender_canonical_file }}"
        content: |
          # Auto-generated sender canonical map
          /^(.+)@{{ inventory_hostname | regex_escape }}$/    ${1}_{{ inventory_hostname }}@{{ public_domain }}
        owner: root
        group: root
        mode: '0644'
      notify: Reload Postfix

    - name: Create recipient_canonical map (inventory_hostname -> {{ team_mailbox }}@{{ public_domain }})
      copy:
        dest: "{{ recipient_canonical_file }}"
        content: |
          # Auto-generated recipient canonical map
          /@{{ inventory_hostname | regex_escape }}$/    {{ team_mailbox }}@{{ public_domain }}
        owner: root
        group: root
        mode: '0644'
      notify: Reload Postfix

    - name: Configure Postfix to use canonical maps
      lineinfile:
        path: /etc/postfix/main.cf
        regexp: '^{{ item.key }} ='
        line: "{{ item.key }} = pcre:{{ item.value }}"
        state: present
      loop:
        - { key: 'sender_canonical_maps', value: "{{ sender_canonical_file }}" }
        - { key: 'recipient_canonical_maps', value: "{{ recipient_canonical_file }}" }
      notify: Reload Postfix

  handlers:
    - name: Reload Postfix
      service:
        name: postfix
        state: reloaded

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions