Looping over tasks in 1.9.4

Hi all,

I am trying to do

  • name: Check if package-1 is installed
    command: dpkg-query -l package-1
    register: deb_check
    ignore_errors: yes
  • name: Check that package-1 designated ports are free
    wait_for: port={{ item }} state=absent timeout=10
    with_items:
  • “{{ package-1.ports }}”

when: deb_check.stderr.find(‘no packages found’) != -1

This works fine. But I want to do this for multiple packages. Doing this for every package is going to insanely increase code repetition. Is there a way to loop over tasks?

Please note that I am using Ansible 1.9.4 which I cannot change.

If any one can help on this.

Thanks
-AliJ