diff --git a/CHANGELOG.md b/CHANGELOG.md index 296612a..438c58c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/) - feat: add bsd-mailx package - feat: add transport map +- feat: add aliases ### Changed diff --git a/README.md b/README.md index 06ec6ad..c89541f 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,15 @@ Install and configure an simple mta with postfix google.com: smtp:127.0.0.1 ``` +* `postfix_aliases` - hash with the aliases + +``` + root: + - abuse + - admin + admin: root@local.loc +``` + ## How to use ``` diff --git a/defaults/main.yml b/defaults/main.yml index a90b837..329faf1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -19,3 +19,4 @@ postfix_default_config: inet_protocols: all postfix_full_config: '{{ postfix_default_config|combine(postfix_config) }}' postfix_transports: {} +postfix_aliases: {} diff --git a/handlers/main.yml b/handlers/main.yml index 5f6be52..9f60728 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -6,3 +6,6 @@ - name: map transport ansible.builtin.command: postmap /etc/postfix/transport + +- name: map aliases + ansible.builtin.command: postalias /etc/postfix/aliases diff --git a/tasks/main.yml b/tasks/main.yml index 81844c4..c70c590 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -7,23 +7,20 @@ tags: postfix - name: copy file configuration - ansible.builtin.template: - src: main.cf.j2 - dest: /etc/postfix/main.cf - owner: root - group: root - mode: 0644 - notify: reload postfix - tags: postfix - -- name: copy transport configuration template: - src: transport.j2 - dest: /etc/postfix/transport + src: '{{ item }}.j2' + dest: '/etc/postfix/{{ item }}' owner: root group: root mode: 0644 - notify: map transport + loop: + - main.cf + - aliases + - transport + notify: + - reload postfix + - map aliases + - map transport tags: postfix - name: enable and start service diff --git a/templates/aliases.j2 b/templates/aliases.j2 new file mode 100644 index 0000000..31c7532 --- /dev/null +++ b/templates/aliases.j2 @@ -0,0 +1,9 @@ +# {{ ansible_managed }} + +{% for alias, redirect in postfix_aliases.items() %} +{% if redirect is string %} +{{ alias }}: {{ redirect }} +{% else %} +{{ alias }}: {{ redirect|join(',') }} +{% endif %} +{% endfor %}