postfix: ansible-lint fixes

This commit is contained in:
Timo Makinen 2022-10-30 17:29:55 +00:00
parent 5864d92d43
commit d72649632f
2 changed files with 115 additions and 100 deletions

View file

@ -1,10 +1,10 @@
--- ---
- name: restart postfix - name: Restart postfix
service: ansible.builtin.service:
name: postfix name: postfix
state: restarted state: restarted
- name: restart stunnel-smtps - name: Restart stunnel-smtps
service: ansible.builtin.service:
name: stunnel-smtps name: stunnel-smtps
state: restarted state: restarted

View file

@ -1,60 +1,60 @@
--- ---
- name: check support - name: Install postfix
fail: ansible.builtin.package:
msg: Role not supported in your system
when: ansible_os_family != "RedHat"
- name: install postfix
package:
name: postfix name: postfix
state: installed state: installed
- name: set postfix as system mta - name: Set postfix as system mta
alternatives: community.general.alternatives:
name: mta name: mta
path: /usr/sbin/sendmail.postfix path: /usr/sbin/sendmail.postfix
- name: configure myhostname - name: Configure myhostname
lineinfile: ansible.builtin.lineinfile:
path: /etc/postfix/main.cf path: /etc/postfix/main.cf
regexp: '^myhostname\s*=' regexp: '^myhostname\s*='
insertafter: '^#myhostname\s*=' insertafter: '^#myhostname\s*='
line: "myhostname = {{ inventory_hostname }}" line: "myhostname = {{ inventory_hostname }}"
notify: restart postfix notify: Restart postfix
- name: configure myorigin - name: Configure myorigin
lineinfile: ansible.builtin.lineinfile:
path: /etc/postfix/main.cf path: /etc/postfix/main.cf
regexp: '^myorigin\s*=' regexp: '^myorigin\s*='
insertafter: '^#myorigin\s*=' insertafter: '^#myorigin\s*='
line: "myorigin = {{ mail_domain }}" line: "myorigin = {{ mail_domain }}"
notify: restart postfix notify: Restart postfix
when: mail_domain is defined when: mail_domain is defined
- name: configure mydestination - name: Configure mydestination
lineinfile: ansible.builtin.lineinfile:
path: /etc/postfix/main.cf path: /etc/postfix/main.cf
regexp: '^mydestination\s*=' regexp: '^mydestination\s*='
insertafter: '^#mydestination\s*=' insertafter: '^#mydestination\s*='
line: 'mydestination = ""' line: 'mydestination = ""'
notify: restart postfix notify: Restart postfix
when: when:
- mail_domain is defined - mail_domain is defined
- mail_server is defined - mail_server is defined
- block: - name: Install stunnel
- name: install stunnel ansible.builtin.package:
package:
name: stunnel name: stunnel
state: installed state: installed
when:
- ansible_distribution_major_version|int <= 7
- mail_server is defined
- name: create group smtps - name: Create group smtps
group: ansible.builtin.group:
name: smtps name: smtps
system: true system: true
when:
- ansible_distribution_major_version|int <= 7
- mail_server is defined
- name: create user smtps - name: Create user smtps
user: ansible.builtin.user:
name: smtps name: smtps
comment: Service Stunnel-SMTPS comment: Service Stunnel-SMTPS
createhome: false createhome: false
@ -62,74 +62,89 @@
home: /var/empty home: /var/empty
shell: /sbin/nologin shell: /sbin/nologin
system: true system: true
when:
- ansible_distribution_major_version|int <= 7
- mail_server is defined
- name: create stunnel config - name: Create stunnel config
template: ansible.builtin.template:
src: stunnel.conf.j2 src: stunnel.conf.j2
dest: /etc/stunnel/smtps.conf dest: /etc/stunnel/smtps.conf
mode: 0644 mode: 0644
owner: root owner: root
group: "{{ ansible_wheel }}" group: "{{ ansible_wheel }}"
notify: restart stunnel-smtps notify: Restart stunnel-smtps
when:
- ansible_distribution_major_version|int <= 7
- mail_server is defined
- name: create stunnel systemd service - name: Create stunnel systemd service
copy: ansible.builtin.copy:
src: stunnel-smtps.service src: stunnel-smtps.service
dest: /etc/systemd/system/stunnel-smtps.service dest: /etc/systemd/system/stunnel-smtps.service
mode: 0644 mode: 0644
owner: root owner: root
group: "{{ ansible_wheel }}" group: "{{ ansible_wheel }}"
notify: restart stunnel-smtps notify: Restart stunnel-smtps
when:
- ansible_distribution_major_version|int <= 7
- mail_server is defined
- name: enable stunnel service - name: Enable stunnel service
service: ansible.builtin.service:
name: stunnel-smtps name: stunnel-smtps
state: started state: started
enabled: true enabled: true
when:
- ansible_distribution_major_version|int <= 7
- mail_server is defined
- name: configure relayhost - name: Configure relayhost
lineinfile: ansible.builtin.lineinfile:
path: /etc/postfix/main.cf path: /etc/postfix/main.cf
regexp: '^relayhost\s*=' regexp: '^relayhost\s*='
insertafter: '^#relayhost\s*=' insertafter: '^#relayhost\s*='
line: "relayhost = [localhost]:2525" line: "relayhost = [localhost]:2525"
notify: restart postfix notify: Restart postfix
when: when:
- ansible_distribution_major_version|int < 8 - ansible_distribution_major_version|int <= 7
- mail_server is defined - mail_server is defined
- block: - name: Configure relayhost
- name: configure relayhost ansible.builtin.lineinfile:
lineinfile:
path: /etc/postfix/main.cf path: /etc/postfix/main.cf
regexp: '^relayhost\s*=' regexp: '^relayhost\s*='
insertafter: '^#relayhost\s*=' insertafter: '^#relayhost\s*='
line: "relayhost = [{{ mail_server }}]:465" line: "relayhost = [{{ mail_server }}]:465"
notify: restart postfix notify: Restart postfix
- name: configure smtp_tls_security_level
lineinfile:
path: /etc/postfix/main.cf
regexp: '^smtp_tls_security_level\s*='
insertafter: '^#?relayhost\s*='
line: "smtp_tls_security_level = encrypt"
notify: restart postfix
- name: configure smtp_tls_wrappermode
lineinfile:
path: /etc/postfix/main.cf
regexp: '^smtp_tls_wrappermode\s*='
insertafter: '^#?relayhost\s*='
line: "smtp_tls_wrappermode = yes"
notify: restart postfix
when: when:
- ansible_distribution_major_version|int >= 8 - ansible_distribution_major_version|int >= 8
- mail_server is defined - mail_server is defined
- name: enable postfix service - name: Configure smtp_tls_security_level
service: ansible.builtin.lineinfile:
path: /etc/postfix/main.cf
regexp: '^smtp_tls_security_level\s*='
insertafter: '^#?relayhost\s*='
line: "smtp_tls_security_level = encrypt"
notify: Restart postfix
when:
- ansible_distribution_major_version|int >= 8
- mail_server is defined
- name: Configure smtp_tls_wrappermode
ansible.builtin.lineinfile:
path: /etc/postfix/main.cf
regexp: '^smtp_tls_wrappermode\s*='
insertafter: '^#?relayhost\s*='
line: "smtp_tls_wrappermode = yes"
notify: Restart postfix
when:
- ansible_distribution_major_version|int >= 8
- mail_server is defined
- name: Enable postfix service
ansible.builtin.service:
name: postfix name: postfix
state: started state: started
enabled: true enabled: true