# jinja2 loop and fact array

**URL:** <https://forum.ansible.com/t/jinja2-loop-and-fact-array/19373>\
**Category:** Ansible Project\
**Created:** [September 28, 2015, 10:51pm UTC](https://forum.ansible.com/t/jinja2-loop-and-fact-array/19373 "2015-09-28T22:51:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trond\_Hindenes](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Trond\_Hindenes](https://forum.ansible.com/u/Trond_Hindenes)\
**Post date:** [September 28, 2015, 10:51pm UTC](https://forum.ansible.com/t/jinja2-loop-and-fact-array/19373/1 "2015-09-28T22:51:13Z")

</div>

I’m sorry if this has come up before - I couldn’t find any answers directly related to my question.

I’m trying to use set\_fact to set an array and use that in a for loop inside a template file.  
In my playbook I have:  
set\_fact: av\_name=“[‘av1’, ‘av2’, ‘av3’]”

And in my template file I’m testing with:

{% for item in av\_name %}  
“this”: “{{ item }}”  
{% endfor %}

Here’s my templated file - jinja2 doesn’t seem to understand the array:

“this”: “[”  
“this”: “'”  
“this”: “a”  
“this”: “v”  
“this”: “1”  
“this”: “'”  
“this”: “,”  
“this”: " "  
“this”: “'”  
“this”: “a”  
“this”: “v”  
“this”: “2”  
“this”: “'”  
“this”: “,”  
“this”: " "  
“this”: “'”  
“this”: “a”  
“this”: “v”  
“this”: “3”  
“this”: “'”  
“this”: “]”

Hopefully I’m doing something wrong!

---

<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:** [September 28, 2015, 11:39pm UTC](https://forum.ansible.com/t/jinja2-loop-and-fact-array/19373/2 "2015-09-28T23:39:13Z")

</div>

set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;av\_name: ['av1', 'av2', 'av3']

or

{% for item in av\_name|list %}
