feat: add aliases

This commit is contained in:
Adrien Waksberg 2021-08-20 18:36:55 +02:00
parent 7ad695f01d
commit 795b2a0b97
6 changed files with 33 additions and 13 deletions

View file

@ -13,6 +13,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
- feat: add bsd-mailx package - feat: add bsd-mailx package
- feat: add transport map - feat: add transport map
- feat: add aliases
### Changed ### Changed

View file

@ -37,6 +37,15 @@ Install and configure an simple mta with postfix
google.com: smtp:127.0.0.1 google.com: smtp:127.0.0.1
``` ```
* `postfix_aliases` - hash with the aliases
```
root:
- abuse
- admin
admin: root@local.loc
```
## How to use ## How to use
``` ```

View file

@ -19,3 +19,4 @@ postfix_default_config:
inet_protocols: all inet_protocols: all
postfix_full_config: '{{ postfix_default_config|combine(postfix_config) }}' postfix_full_config: '{{ postfix_default_config|combine(postfix_config) }}'
postfix_transports: {} postfix_transports: {}
postfix_aliases: {}

View file

@ -6,3 +6,6 @@
- name: map transport - name: map transport
ansible.builtin.command: postmap /etc/postfix/transport ansible.builtin.command: postmap /etc/postfix/transport
- name: map aliases
ansible.builtin.command: postalias /etc/postfix/aliases

View file

@ -7,23 +7,20 @@
tags: postfix tags: postfix
- name: copy file configuration - 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: template:
src: transport.j2 src: '{{ item }}.j2'
dest: /etc/postfix/transport dest: '/etc/postfix/{{ item }}'
owner: root owner: root
group: root group: root
mode: 0644 mode: 0644
notify: map transport loop:
- main.cf
- aliases
- transport
notify:
- reload postfix
- map aliases
- map transport
tags: postfix tags: postfix
- name: enable and start service - name: enable and start service

9
templates/aliases.j2 Normal file
View file

@ -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 %}