---
- name: install the needed packages
  package:
    name:
      - postfix
      - cyrus-sasl
      - cyrus-sasl-plain
  tags:
    - smtp_auth_relay

- name: create the password file
  copy:
    dest: /etc/postfix/sasl_passwd
    content: "{{ smtp_auth_relay_host }} {{ smtp_auth_relay_user }}:{{ smtp_auth_relay_password }}"
    mode: 0600
  register: smtp_relay_password_file
  tags:
    - smtp_auth_relay

- name: regenerate the password db file
  shell: postmap /etc/postfix/sasl_passwd
  when: smtp_relay_password_file.changed
  notify: restart postfix
  tags:
    - smtp_auth_relay
