From 2c7182fe37de5bdd824d049f009a11711e532867 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Thu, 28 Nov 2019 21:47:08 -0600 Subject: [PATCH] Manage postfix aliases --- roles/postfix/defaults/main.yaml | 13 +++++++++++-- roles/postfix/handlers/main.yaml | 3 +++ roles/postfix/tasks/main.yaml | 10 ++++++++++ roles/postfix/templates/aliases.j2 | 13 +++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 roles/postfix/templates/aliases.j2 diff --git a/roles/postfix/defaults/main.yaml b/roles/postfix/defaults/main.yaml index 040e880..3d29a84 100644 --- a/roles/postfix/defaults/main.yaml +++ b/roles/postfix/defaults/main.yaml @@ -6,14 +6,23 @@ postfix_service_name: postfix.service postfix_service_state: started postfix_service_enabled: true +postfix_aliases: + postmaster: root + hostmaster: root + webmaster: root + abuse: root + administrator: root + admin: root + postfix_etc_path: /etc/postfix postfix_sasl_passwd_map_path: "{{ postfix_etc_path }}/sasl_passwd" postfix_sasl_passwd_map: {} postfix_compatibility_level: 2 -postfix_alias_maps: hash:/etc/aliases -postfix_alias_database: hash:/etc/aliases +postfix_aliases_map_path: /etc/aliases +postfix_alias_maps: "hash:{{ postfix_aliases_map_path }}" +postfix_alias_database: "hash:{{ postfix_aliases_map_path }}" postfix_myhostname: "{{ ansible_fqdn }}" postfix_inet_interfaces: loopback-only postfix_smtp_tls_session_cache_database: btree:${data_directory}/smtp_scache diff --git a/roles/postfix/handlers/main.yaml b/roles/postfix/handlers/main.yaml index 5bc195b..35de43b 100644 --- a/roles/postfix/handlers/main.yaml +++ b/roles/postfix/handlers/main.yaml @@ -2,6 +2,9 @@ - name: "postmap sasl_passwd" command: "postmap hash:{{ postfix_sasl_passwd_map_path }}" +- name: "postmap aliases" + command: "postmap hash:{{ postfix_aliases_map_path }}" + - name: reload postfix service: name: "{{ postfix_service_name }}" diff --git a/roles/postfix/tasks/main.yaml b/roles/postfix/tasks/main.yaml index 71ed8e9..860c945 100644 --- a/roles/postfix/tasks/main.yaml +++ b/roles/postfix/tasks/main.yaml @@ -31,6 +31,16 @@ - postmap sasl_passwd - reload postfix +- name: manage /etc/aliases + template: + src: aliases.j2 + dest: "{{ postfix_aliases_map_path }}" + owner: root + group: root + mode: 0644 + notify: + - postmap aliases + - name: manage postfix service service: name: "{{ postfix_service_name }}" diff --git a/roles/postfix/templates/aliases.j2 b/roles/postfix/templates/aliases.j2 new file mode 100644 index 0000000..b27be9f --- /dev/null +++ b/roles/postfix/templates/aliases.j2 @@ -0,0 +1,13 @@ +# {{ ansible_managed }} + +{% if postfix_aliases is defined and + postfix_aliases is mapping and + postfix_aliases | length %} +{% for k, v in postfix_aliases.items() %} +{% if v is string %} +{{ k }} {{ v }} +{% else %} +{{ k }} {{ v | join(', ') }} +{% endif %} +{% endfor %} +{% endif %}