# How to use 'with\_items' based on variable?

**URL:** <https://forum.ansible.com/t/how-to-use-with-items-based-on-variable/29338>\
**Category:** Ansible Project\
**Created:** [December 28, 2018, 8:03pm UTC](https://forum.ansible.com/t/how-to-use-with-items-based-on-variable/29338 "2018-12-28T20:03:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bharath\_Kumar2](https://avatars.discourse-cdn.com/v4/letter/b/91b2a8/32.png) [@Bharath\_Kumar2](https://forum.ansible.com/u/Bharath_Kumar2)\
**Post date:** [December 28, 2018, 8:03pm UTC](https://forum.ansible.com/t/how-to-use-with-items-based-on-variable/29338/1 "2018-12-28T20:03:27Z")

</div>

Hello Ansible Experts,

I am creating a Role, which has a task to download multiple files from an URL, and, for that, I am using get\_url module. Since, get\_url cant download files recursively, I have been trying to use ‘with\_items’.

Role Snippets Below.

/defaults/main.yml  
`

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [December 28, 2018, 8:47pm UTC](https://forum.ansible.com/t/how-to-use-with-items-based-on-variable/29338/2 "2018-12-28T20:47:40Z")

</div>

Try

files: "{{ lookup('vars', dir ~ '\_files' }}"

V/r,  
James Cassell

---

<div class="post-metadata">

**Author:** ![Bharath\_Kumar2](https://avatars.discourse-cdn.com/v4/letter/b/91b2a8/32.png) [@Bharath\_Kumar2](https://forum.ansible.com/u/Bharath_Kumar2)\
**Post date:** [December 31, 2018, 6:37pm UTC](https://forum.ansible.com/t/how-to-use-with-items-based-on-variable/29338/3 "2018-12-31T18:37:55Z")

</div>

Thanks very much James for your advise. Was able to achieve what was intended, but there seems to be another problem.

Updated the code as below, and, Ansible is passing the list of items to the get\_url.

`

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [December 31, 2018, 9:09pm UTC](https://forum.ansible.com/t/how-to-use-with-items-based-on-variable/29338/4 "2018-12-31T21:09:14Z")

</div>

with\_items: "{{ lookup('vars', dir ~'\_files') }}"

V/r,  
James Cassell
