jinja2 loop and fact array

71 views
Skip to first unread message

Trond Hindenes

unread,
Sep 28, 2015, 6:51:13 PM9/28/15
to Ansible Project
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!


Brian Coca

unread,
Sep 28, 2015, 7:39:19 PM9/28/15
to Ansible Project
set_fact:
av_name: ['av1', 'av2', 'av3']

or

{% for item in av_name|list %}



--
Brian Coca
Reply all
Reply to author
Forward
0 new messages