--- - name: Disable postfix on all hosts hosts: all tasks: - name: Check if postfix is installed ansible.builtin.command: which postfix register: postfix_check changed_when: false failed_when: false - name: Stop and disable postfix ansible.builtin.systemd: name: postfix state: stopped enabled: false when: postfix_check.rc == 0 - name: Set postfix to localhost-only ansible.builtin.lineinfile: path: /etc/postfix/main.cf regexp: '^inet_interfaces\s*=' line: 'inet_interfaces = loopback-only' when: postfix_check.rc == 0 - name: Set relayhost to empty ansible.builtin.lineinfile: path: /etc/postfix/main.cf regexp: '^relayhost\s*=' line: 'relayhost =' when: postfix_check.rc == 0