# for loop in a playbook task

**URL:** <https://forum.ansible.com/t/for-loop-in-a-playbook-task/24043>\
**Category:** Ansible Project\
**Tags:** galaxy-ng\
**Created:** [March 23, 2017, 1:30pm UTC](https://forum.ansible.com/t/for-loop-in-a-playbook-task/24043 "2017-03-23T13:30:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Marquez](https://avatars.discourse-cdn.com/v4/letter/e/9d8465/32.png) [@Eric\_Marquez](https://forum.ansible.com/u/Eric_Marquez)\
**Post date:** [March 23, 2017, 1:30pm UTC](https://forum.ansible.com/t/for-loop-in-a-playbook-task/24043/1 "2017-03-23T13:30:20Z")

</div>

Is it possible to create a for loop in a task? I have a switch Access-Control list I need to build. In my host\_vars file I have a YAML object that contains all the source and destination addresses in an array. This way I can also control the sequence number without having to explicitly document an index number. In Galaxy the OEM has a ACL module I can reference but it looks like I would need to breakdown all the items in the array within the task.yml file. Is there a simpler way were I can call an for loop in the task to loop through all the LINE's I have in my variable file?  
This would then allow me to generate the dellos\_system seqlist without having to explicitly set every ACL entry. I have a very large set of ACL's to build and using the Galaxy example would be very inefficient, and cause lots of maintenance if I needed to change my ACL setup or modify it in the future. I'm looking for a more modular way to do this.

Galaxy module: [https://galaxy.ansible.com/Dell-Networking/dellos-acl/](https://galaxy.ansible.com/Dell-Networking/dellos-acl/)

Here's an example of a very small ACL.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 23, 2017, 1:34pm UTC](https://forum.ansible.com/t/for-loop-in-a-playbook-task/24043/2 "2017-03-23T13:34:28Z")

</div>

with\_ \<= is basically a for loop, the task runs 'for item in  
with\_\<lookup\>: parameters', with\_ always returns a list, which the  
task iterates over and the 'loop variable' is 'item'.

you can use loop\_control to change the loop variable.
