---
- name: Create a postmapped file
  hosts: all

  vars:
    postfix_files:
      - name: test
        content: test
        postmap: true

  tasks:
    - name: Run the role with test postmap file
      include_role:
        name: linux-system-roles.postfix
        public: true

    - name: Check if postmap file exists
      stat:
        path: /etc/postfix/test{{ __test_file_suffix }}
      register: test_file
      changed_when: false
      vars:
        __test_file_suffix: "{{ '.lmdb' if ansible_facts['os_family'] == 'RedHat'
          and ansible_facts['distribution'] != 'Fedora'
          and ansible_facts['distribution_major_version'] is version('10', '>=')
          else '.db' }}"

    - name: Assert file is present
      assert:
        that: test_file.stat.exists

    - name: Clean up test files
      file:
        path: "{{ item }}"
        state: absent
      loop:
        - /etc/postfix/test
        - /etc/postfix/test.db
