Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Only tested on ubuntu for now.
#### Variables

```yaml
postfix_enabled: yes # The role is enabled
postfix_enabled: true # The role is enabled

postfix_smtpd_use_tls: yes
postfix_myhostname: "{{inventory_hostname}}"
postfix_smtpd_use_tls: true
postfix_myhostname: "{{ inventory_hostname }}"
postfix_myorigin: $myhostname
postfix_smtp_sasl_auth_enable: yes
postfix_smtp_sasl_auth_enable: true
postfix_smtp_tls_cafile: "/etc/ssl/certs/Thawte_Premium_Server_CA.pem"
postfix_relayhost:
postfix_mynetworks: "127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128"
Expand Down
16 changes: 8 additions & 8 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---

postfix_enabled: yes # The role is enabled
postfix_enabled: true # The role is enabled

postfix_smtpd_use_tls: yes
postfix_myhostname: "{{inventory_hostname}}"
postfix_smtpd_use_tls: true
postfix_myhostname: "{{ inventory_hostname }}"
postfix_myorigin: $myhostname
postfix_smtp_sasl_auth_enable: yes
postfix_smtp_sasl_auth_enable: true
postfix_smtp_tls_CApath: "/etc/ssl/certs"
postfix_smtp_use_tls: yes
postfix_smtp_use_tls: true
postfix_relayhost:
postfix_mynetworks: "127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128"
postfix_inet_interfaces: loopback-only
Expand All @@ -20,9 +20,9 @@ postfix_os_service: ""
postfix_generic_maps: ""

# Install opendkim and setup postfix to use DKIM
postfix_dkim: no
postfix_dkim: false
postfix_dkim_domains:
- "{{inventory_hostname}}"
- "{{ inventory_hostname }}"

# Relay all mail going to local users (e.g. root or cron) to another mail address
postfix_local_user_relay_address: ""
Expand All @@ -44,7 +44,7 @@ maximal_backoff_time: 15m
minimal_backoff_time: 5m
queue_run_delay: 5m

postfix_tls_generate: False
postfix_tls_generate: false
postfix_ssl_subject: ""
postfix_tls_cert_file: "/etc/ssl/certs/ssl-cert-snakeoil.pem"
postfix_tls_key_file: "/etc/ssl/private/ssl-cert-snakeoil.key"
Expand Down
4 changes: 2 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
notify: postfix send test mail

- name: "postfix send test mail"
shell: echo "Test mail from new/updated postfix at" `hostname` | mail {{postfix_send_test_mail_to}} -s "Test SMTP `hostname`"
when: postfix_send_test_mail_to != ""
shell: echo "Test mail from new/updated postfix at" `hostname` | mail {{ postfix_send_test_mail_to }} -s "Test SMTP `hostname`"
when: postfix_send_test_mail_to | length > 0
3 changes: 2 additions & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ galaxy_info:
company: Stouts
description: Manage postfix
license: MIT
min_ansible_version: 2.8
platforms:
- name: Ubuntu
versions:
Expand All @@ -17,6 +18,6 @@ galaxy_info:
- name: CentOS
versions:
- all
categories:
galaxy_tags:
- system
- networking
6 changes: 3 additions & 3 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
notify: postfix restart

- name: Configure postfix pt. 1
template: src={{item}}.j2 dest=/etc/postfix/{{item}} owner=root group=root mode=0644
template: src={{ item }}.j2 dest=/etc/postfix/{{ item }} owner=root group=root mode=0644
notify: postfix restart
with_items:
- main.cf
Expand Down Expand Up @@ -38,11 +38,11 @@
- name: Configure postfix local user relay
template: src=virtual.j2 dest=/etc/postfix/virtual-pcre owner=root group=root mode=0644
notify: postfix restart
when: postfix_local_user_relay_address != ""
when: postfix_local_user_relay_address | length > 0

- name: Configure postfix sender canonical maps
template: src=sender_canonical_maps.j2 dest=/etc/postfix/sender_canonical_maps
when: postfix_rewrite_sender_address != ""
when: postfix_rewrite_sender_address | length > 0
notify: postfix restart

- name: Configure SystemD
Expand Down
23 changes: 13 additions & 10 deletions tasks/install.deb.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
---

- name: Install requirements (Debian)
apt: name={{item}} update_cache=yes
with_items:
- postfix
- ca-certificates
- mailutils
- libsasl2-modules
apt:
update_cache: true
name:
- postfix
- ca-certificates
- mailutils
- libsasl2-modules


- name: Install DKIM requirements (Debian)
apt: name={{item}}
when: postfix_dkim
with_items:
- opendkim
- opendkim-tools
- opendkim
- opendkim-tools

- name: Install postfix-pcre
apt: pkg=postfix-pcre
when: postfix_rewrite_sender_address != "" or postfix_local_user_relay_address != ""
apt:
name: postfix-pcre
when: postfix_rewrite_sender_address | length > 0 or postfix_local_user_relay_address | length > 0
16 changes: 8 additions & 8 deletions tasks/opendkim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
notify: postfix opendkim restart

- name: Create DKIM directories
file: state=directory path=/etc/opendkim/keys/{{item}} recurse=true owner=root mode=0755
with_items: "{{postfix_dkim_domains}}"
file: state=directory path=/etc/opendkim/keys/{{ item }} recurse=true owner=root mode=0755
with_items: "{{ postfix_dkim_domains }}"
notify: postfix opendkim restart

- name: Generate DKIM key
command: opendkim-genkey -s mail -d "{{item}}"
command: opendkim-genkey -s mail -d "{{ item }}"
args:
chdir: "/etc/opendkim/keys/{{item}}"
creates: "/etc/opendkim/keys/{{item}}/mail.private"
with_items: "{{postfix_dkim_domains}}"
chdir: "/etc/opendkim/keys/{{ item }}"
creates: "/etc/opendkim/keys/{{ item }}/mail.private"
with_items: "{{ postfix_dkim_domains }}"
notify: postfix opendkim restart

- name: Change DKIM key permissions
file: path=/etc/opendkim/keys/{{item}}/mail.private owner=opendkim group=opendkim mode=600
with_items: "{{postfix_dkim_domains}}"
file: path=/etc/opendkim/keys/{{ item }}/mail.private owner=opendkim group=opendkim mode=600
with_items: "{{ postfix_dkim_domains }}"

- name: Configure opendkim pt. 1
template: src=opendkim/opendkim.conf.j2 dest=/etc/opendkim.conf owner=root group=root mode=0644
Expand Down
38 changes: 19 additions & 19 deletions templates/main.cf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

{% if postfix_smtp_tls_wrappermode is defined %}
smtp_tls_wrappermode = {{postfix_smtp_tls_wrappermode}}
smtp_tls_wrappermode = {{ postfix_smtp_tls_wrappermode }}
{% endif %}

{% if postfix_smtp_tls_security_level is defined %}
smtp_tls_security_level = {{postfix_smtp_tls_security_level}}
smtp_tls_security_level = {{ postfix_smtp_tls_security_level }}
{% endif %}

{% endif %}

myhostname = {{postfix_myhostname}}
myorigin = {{postfix_myorigin}}
myhostname = {{ postfix_myhostname }}
myorigin = {{ postfix_myorigin }}
alias_maps = hash:/etc/aliases
smtp_generic_maps = hash:/etc/postfix/generic
{% if postfix_rewrite_sender_address %}
sender_canonical_maps = pcre:/etc/postfix/sender_canonical_maps
{% endif %}
alias_database = hash:/etc/aliases
mydestination = {{postfix_mydestination}}
mydestination = {{ postfix_mydestination }}

{% if postfix_local_user_relay_address %}
# Optional catch-all destination for unknown local(8) recipients:
Expand All @@ -56,36 +56,36 @@ smtp_sasl_security_options = {{ postfix_smtp_sasl_security_options }}
{% if postfix_smtp_use_tls %}
smtp_use_tls = yes
smtp_tls_security_level = encrypt
smtp_tls_CApath = {{postfix_smtp_tls_CApath}}
smtp_tls_CApath = {{ postfix_smtp_tls_CApath }}
{% endif %}
{% endif %}

{% if postfix_relayhost %}
relayhost = {{postfix_relayhost}}
relayhost = {{ postfix_relayhost }}
{% endif %}
mynetworks = {{postfix_mynetworks}}
mynetworks = {{ postfix_mynetworks }}
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = {{postfix_inet_interfaces}}
inet_protocols = {{postfix_inet_protocols}}
inet_interfaces = {{ postfix_inet_interfaces }}
inet_protocols = {{ postfix_inet_protocols }}
{% if postfix_smtpd_relay_restrictions|default(None) %}
smtpd_relay_restrictions = {{postfix_smtpd_relay_restrictions}}
smtpd_relay_restrictions = {{ postfix_smtpd_relay_restrictions }}
{% endif %}

{% if postfix_mydomain is defined %}
mydomain = {{postfix_mydomain}}
mydomain = {{ postfix_mydomain }}
{% endif %}

{% if postfix_notify_classes is defined %}
notify_classes = {{postfix_notify_classes}}
notify_classes = {{ postfix_notify_classes }}
{% endif %}

{% if postfix_use_procmail is defined %}
mailbox_command = /usr/bin/procmail -a "$EXTENSION"
{% endif %}

{% if postfix_notify_classes is defined %}
notify_classes = {{postfix_notify_classes}}
notify_classes = {{ postfix_notify_classes }}
{% endif %}

{% if postfix_dkim %}
Expand All @@ -96,8 +96,8 @@ non_smtpd_milters = inet:localhost:12301
{% endif %}

# Queue
bounce_queue_lifetime = {{bounce_queue_lifetime}}
maximal_queue_lifetime = {{maximal_queue_lifetime}}
maximal_backoff_time = {{maximal_backoff_time}}
minimal_backoff_time = {{minimal_backoff_time}}
queue_run_delay = {{queue_run_delay}}
bounce_queue_lifetime = {{ bounce_queue_lifetime }}
maximal_queue_lifetime = {{ maximal_queue_lifetime }}
maximal_backoff_time = {{ maximal_backoff_time }}
minimal_backoff_time = {{ minimal_backoff_time }}
queue_run_delay = {{ queue_run_delay }}
2 changes: 1 addition & 1 deletion templates/opendkim/KeyTable.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{%for item in postfix_dkim_domains -%}
mail._domainkey.{{item}} {{item}}:mail:/etc/opendkim/keys/{{item}}/mail.private
mail._domainkey.{{ item }} {{ item }}:mail:/etc/opendkim/keys/{{ item }}/mail.private
{%endfor %}
2 changes: 1 addition & 1 deletion templates/opendkim/SigningTable.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% for item in postfix_dkim_domains -%}
*@{{item}} mail._domainkey.{{item}}
*@{{ item }} mail._domainkey.{{ item }}
{% endfor %}
2 changes: 1 addition & 1 deletion templates/opendkim/TrustedHosts.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ localhost
192.168.0.1/24

{%for item in postfix_dkim_domains -%}
*.{{item}}
*.{{ item }}
{%endfor %}
2 changes: 1 addition & 1 deletion templates/sender_canonical_maps.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% if postfix_rewrite_sender_address %}
/.+/ {{postfix_rewrite_sender_address}}
/.+/ {{ postfix_rewrite_sender_address }}
{% endif %}
2 changes: 1 addition & 1 deletion templates/virtual.j2
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/.+@localhost/ {{postfix_local_user_relay_address}}
/.+@localhost/ {{ postfix_local_user_relay_address }}