---
- name: Manage the POSTSRSD packages in EL systems
  block:
    - name: Install the COPR repo that publishes postsrsd
      template:
        src: copr-postsrsd.repo.j2
        dest: /etc/yum.repos.d/copr-postsrsd.repo
        owner: root
        group: root
        mode: 0644

    - name: Install the POSTSRSD packages on EL
      yum:
        pkg: '{{ postfix_srs_pkg }}'
        state: present

  when: ansible_distribution_file_variety == "RedHat"
  tags: ['postfix', 'postfix_postsrsd', 'postsrsd']

- name: Manage the POSTSRSD packages in DEB systems
  block:
    - name: Install the POSTSRSD packages on DEB
      apt:
        pkg: '{{ postfix_srs_pkg }}'
        state: present
        cache_valid_time: 1800

  when: ansible_distribution_file_variety == "Debian"
  tags: ['postfix', 'postfix_postsrsd', 'postsrsd']

- name: POSTSRSD configuration
  block:
    - name: Install the postsrsd secret. After the first start of the service
      template:
        src: postsrsd.secret.j2
        dest: '{{ postfix_srs_secret_file }}'
        mode: 0440
        owner: '{{ postfix_srs_user }}'
        group: 'root'
      notify: restart postsrsd

    - name: Install the postsrsd configuration file
      template:
        src: 'postsrsd.default.j2'
        dest: '{{ postfix_srs_conf_file }}'
        owner: root
        group: root
        mode: 0644
      notify: restart postsrsd

  tags: ['postfix', 'postfix_postsrsd', 'postsrsd', 'postfix_conf', 'postsrsd_conf']

- name: Manage the POSTSRSD service
  block:
    - name: Ensure that the postsrsd service is started and enabled
      service:
        name: postsrsd
        state: started
        enabled: true

  tags: ['postfix', 'postfix_postsrsd', 'postsrsd']