# Generate a dynamic list to be used by with\_items

**URL:** <https://forum.ansible.com/t/generate-a-dynamic-list-to-be-used-by-with-items/20478>\
**Category:** Ansible Developer\
**Created:** [February 8, 2016, 12:12am UTC](https://forum.ansible.com/t/generate-a-dynamic-list-to-be-used-by-with-items/20478 "2016-02-08T00:12:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hce](https://avatars.discourse-cdn.com/v4/letter/h/c0e974/32.png) [@hce](https://forum.ansible.com/u/hce)\
**Post date:** [February 8, 2016, 12:12am UTC](https://forum.ansible.com/t/generate-a-dynamic-list-to-be-used-by-with-items/20478/1 "2016-02-08T00:12:52Z")

</div>

Hi,

I thought the following should work, but I got a syntax error. Can the yml condition check syntax be used inside with\_items? If not, how can I generate a dynamic list in the role to be used by with\_items (register ??)? Thank you very much and appreciate any clues to fix following statement or workarounds.

- name: install scripts  
copy: dest={{ home }}/scripts/{{ item }} src=scripts/{{ item }} mode=755  
with\_items:  
{% set script\_list = %}  
{% for s in services %}  
{% for g in s.groups %}  
{% if g in groups %}  
{% if script\_list.append(s.script) %}  
{% endif %}  
{% endif %}  
{% endfor %}  
{% endfor %}  
{% for script in script\_list | unique %}  
{{ script }}  
{% endif %}

---

<div class="post-metadata">

**Author:** ![hce](https://avatars.discourse-cdn.com/v4/letter/h/c0e974/32.png) [@hce](https://forum.ansible.com/u/hce)\
**Post date:** [February 8, 2016, 12:23am UTC](https://forum.ansible.com/t/generate-a-dynamic-list-to-be-used-by-with-items/20478/2 "2016-02-08T00:23:21Z")

</div>

Forgot the error message:

Note: The error may actually appear before this position: line 17, column 6

with\_items:  
{% set script\_list = %}  
^

---

<div class="post-metadata">

**Author:** ![hce](https://avatars.discourse-cdn.com/v4/letter/h/c0e974/32.png) [@hce](https://forum.ansible.com/u/hce)\
**Post date:** [February 8, 2016, 12:25am UTC](https://forum.ansible.com/t/generate-a-dynamic-list-to-be-used-by-with-items/20478/3 "2016-02-08T00:25:18Z")

</div>

Also fixed the list line:

{% for script in script\_list | unique %}  
{{ script }}  
{% endfor %}

---

<div class="post-metadata">

**Author:** ![hce](https://avatars.discourse-cdn.com/v4/letter/h/c0e974/32.png) [@hce](https://forum.ansible.com/u/hce)\
**Post date:** [February 9, 2016, 1:14am UTC](https://forum.ansible.com/t/generate-a-dynamic-list-to-be-used-by-with-items/20478/4 "2016-02-09T01:14:31Z")

</div>

Don’t worry about it, don’t need it any more.

Thank you.
