ansible-postfix icon indicating copy to clipboard operation
ansible-postfix copied to clipboard

Old entries in recipient_canonical_maps/sender_canonical_maps/aliases are not cleaned up

Open adborden opened this issue 5 years ago • 8 comments

If I run the playbook with:

recipient_canonical_maps:
  - recipient: root
  - rewrite: [email protected]

Then I run the playbook with:

recipient_canonical_maps:
  - recipient: postmaster
  - rewrite: [email protected]

And then I inspect /etc/postfix/recipient_canonical_maps

$ cat /etc/postfix/recipient_canonical_maps
root [email protected]
postmaster [email protected]

adborden avatar Jun 19 '20 22:06 adborden

That's indeed a problem. Using the lineinfile module is not appropriate here. copy with content parameter or template would work better. Also both of these are more efficient for a larger number of entries in the list.

racke avatar Nov 11 '20 16:11 racke

For example:

- name: configure recipient canonical maps
  copy:
    dest: "{{ postfix_recipient_canonical_maps_file }}"
    content: |
      {% for item in postfix_recipient_canonical_maps %}
      {{ item.recipient }} {{ item.rewrite }}
      {% endfor %}
    owner: root
    group: root
    mode: 0644

Disadvantage: leaves an empty line in the file when the value is an empty array.

racke avatar Nov 12 '20 12:11 racke

@racke Maybe add a when: postfix_recipient_canonical_maps | lenght

tersmitten avatar Nov 12 '20 15:11 tersmitten

I thought about that, but if we do that it is still possible that we get stale entries from previous runs. I think it should be possible to use the same template for all of these tasks (instead of using copy).

racke avatar Nov 12 '20 15:11 racke

I guess I prefer a template too

tersmitten avatar Nov 12 '20 15:11 tersmitten

I faced this today but with ..._generic_maps 😢 I couldn't understand where the issue was for quite some time.

lineinfile-based implementation for stuff like this (with user-provided keys) gives more cons than pros.

GarrisonD avatar Jun 04 '22 19:06 GarrisonD

Definitely ... and the performance will suffer for a large number of entries.

racke avatar Jun 06 '22 06:06 racke

Feel free to create a PR

tersmitten avatar Mar 26 '24 10:03 tersmitten