From 15355de33cff4caf267dceda52af459e68a9bfaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=2E=20Alberto=20Gim=C3=A9nez?= Date: Sun, 17 May 2020 13:37:27 +0200 Subject: [PATCH] Manage /etc/aliases with the template module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using the `lineinfile` module causes the deletion of aliases in the vars files not to be reflected in the actual `/etc/aliases` file, so we may end up with dangling entries. Using a template to manage the whole file makes sense since this file should be "owned" by the postfix installation/configuration, so we want it to be rebuilt as a whole from the vars configuration instead of just editing some lines. Closes #78 Signed-off-by: L. Alberto Giménez --- tasks/main.yml | 8 ++------ templates/etc/aliases.j2 | 7 +++++++ 2 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 templates/etc/aliases.j2 diff --git a/tasks/main.yml b/tasks/main.yml index d2d1350..29d8634 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -75,16 +75,12 @@ - postfix-sasl-passwd - name: configure aliases - lineinfile: + template: + src: etc/aliases.j2 dest: "{{ postfix_aliases_file }}" - regexp: '^{{ item.user | regex_escape }}.*' - line: '{{ item.user }}: {{ item.alias }}' owner: root group: root mode: 0644 - create: true - state: present - with_items: "{{ postfix_aliases }}" notify: - new aliases - restart postfix diff --git a/templates/etc/aliases.j2 b/templates/etc/aliases.j2 new file mode 100644 index 0000000..8dedf5e --- /dev/null +++ b/templates/etc/aliases.j2 @@ -0,0 +1,7 @@ +{{ ansible_managed | comment }} +# See man 5 aliases for format + +postmaster: root +{% for alias in postfix_aliases %} +{{ alias.user }}: {{ alias.alias }} +{% endfor %}