Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
adborden opened this issue Jun 19, 2020 · 8 comments

Comments

@adborden
Copy link

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
Copy link
Contributor

racke commented Nov 11, 2020

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
Copy link
Contributor

racke commented Nov 12, 2020

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
Copy link
Member

@racke Maybe add a when: postfix_recipient_canonical_maps | lenght

@racke
Copy link
Contributor

racke commented Nov 12, 2020

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
Copy link
Member

I guess I prefer a template too

@tersmitten tersmitten added this to the 4.0.0 milestone Dec 30, 2020
@GarrisonD
Copy link

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
Copy link
Contributor

racke commented Jun 6, 2022

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

@tersmitten
Copy link
Member

Feel free to create a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants