Open adborden opened 4 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.
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 Maybe add a when: postfix_recipient_canonical_maps | lenght
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).
I guess I prefer a template too
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.
Definitely ... and the performance will suffer for a large number of entries.
Feel free to create a PR
If I run the playbook with:
Then I run the playbook with:
And then I inspect /etc/postfix/recipient_canonical_maps