---
- name: Test setting previous=replaced with postfix_conf
  hosts: all
  tasks:
    - name: Run the role with previous=replaced only
      include_role:
        name: redhat.rhel_system_roles.postfix
        public: true
      vars:
        postfix_manage_firewall: true
        postfix_manage_selinux: false
        postfix_conf:
          previous: replaced

    - name: Check firewall and selinux status
      include_tasks: check_firewall_selinux.yml

    - name: Run the role to configure relay_domains and relayhost
      include_role:
        name: redhat.rhel_system_roles.postfix
        public: true
      vars:
        postfix_manage_firewall: true
        postfix_manage_selinux: true
        postfix_conf:
          relay_domains: London
          relayhost: example.com

    - name: Flush handlers
      meta: flush_handlers

    - name: Check firewall and selinux status
      include_tasks: check_firewall_selinux.yml

    - name: Reset all settings and configure relay_domains
      include_role:
        name: redhat.rhel_system_roles.postfix
      vars:
        postfix_conf:
          previous: replaced
          relay_domains: Liverpool city

    - name: Flush handlers
      meta: flush_handlers

    - name: Print postfix settings that have explicit value set
      command: postconf -n
      register: __postfix_explicit_config
      changed_when: false

    - name: Verify that relayhost is unset and relay_domains is set
      assert:
        that:
          - __postfix_explicit_config.stdout is search( "relay_domains = Liverpool city")
          - __postfix_explicit_config.stdout is not search("relayhost")
