# Looping over tasks in 1.9.4

**URL:** <https://forum.ansible.com/t/looping-over-tasks-in-1-9-4/23051>\
**Category:** Ansible Project\
**Created:** [November 18, 2016, 8:19am UTC](https://forum.ansible.com/t/looping-over-tasks-in-1-9-4/23051 "2016-11-18T08:19:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ali\_Jabir](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Ali\_Jabir](https://forum.ansible.com/u/Ali_Jabir)\
**Post date:** [November 18, 2016, 8:19am UTC](https://forum.ansible.com/t/looping-over-tasks-in-1-9-4/23051/1 "2016-11-18T08:19:38Z")

</div>

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
