Skip to content

Commit

Permalink
Manage /etc/aliases with the template module
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
agimenez committed May 17, 2020
1 parent d0529a7 commit 15355de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 2 additions & 6 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions templates/etc/aliases.j2
Original file line number Diff line number Diff line change
@@ -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 %}

0 comments on commit 15355de

Please sign in to comment.