- name: find all installed versions of mail-transport-agent except postfix shell: aptitude search '~i~Pmail-transport-agent' | sed -e 's/^...\(.*\)/\1/' | awk '{ print $1 }' | grep -v postfix || /bin/true register: mtas - name: purge MTAs other than postfix apt: name: "{{ item }}" state: absent purge: yes loop: "{{ mtas.stdout_lines|list }}"