Initial commit with previous code

This commit is contained in:
Antonio J. Delgado 2022-10-11 10:18:52 +03:00
commit 28dc008fc7
5 changed files with 74 additions and 0 deletions

25
defaults/main.yml Normal file
View file

@ -0,0 +1,25 @@
---
primary_mail_server: mail.example.org
primary_mail_server_port: 587
mail_domains:
- example.org
- example.com
mail_aliases:
- local_name: postmaster
mail: mailadmin@example.org
mail_trusted_networks:
- 127.0.0.0/8
- 192.168.1.0/24
mail_user: backup_mx
mail_user_password: "{{ vault_backup_mx_user_password }}"
# Keep this bare minimun to keep the backup MX functionality
postfix_config:
mydestination: 'localhost; localhost.localdomain'
myhostname: "{{ ansible_hostname }}"
mynetworks: "{{ mail_trusted_networks | join(' ') }}"
smtpd_recipient_restrictions: 'permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination'
relayhost: "{{ primary_mail_server }}"
relay_domains: "$mydestination {{ mail_domains |join(' ') }}"
relay_recipient_maps: ''
virtual_alias_domains: ''
virtual_mailbox_domains: ''

11
handlers/main.yml Normal file
View file

@ -0,0 +1,11 @@
---
- name: Refresh aliases
shell: newaliases
- name: Reload postfix
service:
name: postfix
state: restarted
- name: Reload Systemd daemon
shell: systemctl daemon-reload
- name: Update passwords
shell: /usr/sbin/postmap /etc/postfix/smtp_passwords

28
tasks/configure.yml Normal file
View file

@ -0,0 +1,28 @@
---
- name: Ensure aliases are present
lineinfile:
path: '/etc/aliases'
regexp: "^{{ item.local_name }}: "
line: "{{ item.local_name }}: {{ item.mail }}"
create: yes
backup: yes
loop: "{{ mail_aliases }}"
notify: Refresh aliases
- name: Ensure mail passwords is configured
lineinfile:
path: /etc/postfix/smtp_passwords
regexp: "^{{ primary_mail_server }}::{{ primary_mail_server_port }} "
line: "{{ primary_mail_server }}::{{ primary_mail_server_port }} {{ mail_user }}@{{ mail_domains[0] }}:{{ mail_user_password }}"
create: yes
backup: yes
notify: Update passwords
- name: Ensure postfix is configured
lineinfile:
path: /etc/postfix/main.cf
regexp: "^{{ item.key }}"
line: '{{ item.key }} = {{ item.value }}'
backup: yes
loop: "{{ postfix_config | dict2items }}"
notify: Reload postfix

5
tasks/install.yml Normal file
View file

@ -0,0 +1,5 @@
---
- name: Ensure software is installed
package:
name:
- postfix

5
tasks/main.yml Normal file
View file

@ -0,0 +1,5 @@
---
- name: Ensure installation of backup mail services
include_tasks: install.yml
- name: Ensure configuration of backup mail services
include_tasks: configure.yml