mailrelay.yml 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. ---
  2. # start of mailrelay playbook
  3. - name: create mail relay servers
  4. hosts: mailrelay
  5. user: devops
  6. become: true
  7. tasks:
  8. - name: install postfix package
  9. yum:
  10. name: postfix
  11. state: installed
  12. - name: install mail config files
  13. template:
  14. src: postfix-relay-main.conf.j2
  15. dest: /etc/postfix/main.cf
  16. owner: root
  17. group: root
  18. mode: 0644
  19. notify: restart postfix
  20. - name: check main.cf file
  21. stat: path=/etc/postfix/main.cf
  22. register: maincf
  23. - name: verify main.cf file exists
  24. debug: msg="The main.cf file exists"
  25. when: maincf.stat.exists is defined
  26. - name: start and enable mail services
  27. service:
  28. name: postfix
  29. state: started
  30. enabled: yes
  31. - name: check for always_bcc
  32. command: /usr/sbin/postconf always_bcc
  33. register: bcc_state
  34. ignore_errors: true
  35. - name: email notification of always_bcc config
  36. mail:
  37. to: student@serverb.example.com
  38. subject: 'always_bcc setting is not empty'
  39. body: "always_bcc is {{bcc_state.stdout}}"
  40. when: bcc_state.stdout != 'always_bcc ='
  41. - name: POSTFIX FIREWALL CONFIG
  42. firewalld:
  43. state: enabled
  44. permanent: true
  45. immediate: true
  46. service: smtp
  47. handlers:
  48. - name: restart postfix
  49. service:
  50. name: postfix
  51. state: restarted
  52. # end of mailrelay play