Oefenweb / ansible-postfix

Ansible role to set up postfix in Debian-like systems
MIT License
174 stars 82 forks source link

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

Open adborden opened 4 years ago

adborden commented 4 years ago

If I run the playbook with:

recipient_canonical_maps:
  - recipient: root
  - rewrite: me@example.com

Then I run the playbook with:

recipient_canonical_maps:
  - recipient: postmaster
  - rewrite: me@example.com

And then I inspect /etc/postfix/recipient_canonical_maps

$ cat /etc/postfix/recipient_canonical_maps
root me@example.com
postmaster me@example.com
racke commented 3 years ago

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 commented 3 years ago

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.

tersmitten commented 3 years ago

@racke Maybe add a when: postfix_recipient_canonical_maps | lenght

racke commented 3 years ago

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).

tersmitten commented 3 years ago

I guess I prefer a template too

GarrisonD commented 2 years ago

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.

racke commented 2 years ago

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

tersmitten commented 7 months ago

Feel free to create a PR