# Defining a list inside variable file, to allow for jinja loops for that list

**URL:** <https://forum.ansible.com/t/defining-a-list-inside-variable-file-to-allow-for-jinja-loops-for-that-list/15157>\
**Category:** Ansible Project\
**Created:** [May 5, 2014, 1:27pm UTC](https://forum.ansible.com/t/defining-a-list-inside-variable-file-to-allow-for-jinja-loops-for-that-list/15157 "2014-05-05T13:27:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg\_cox](https://avatars.discourse-cdn.com/v4/letter/g/35a633/32.png) [@greg\_cox](https://forum.ansible.com/u/greg_cox)\
**Post date:** [May 5, 2014, 1:27pm UTC](https://forum.ansible.com/t/defining-a-list-inside-variable-file-to-allow-for-jinja-loops-for-that-list/15157/1 "2014-05-05T13:27:57Z")

</div>

It seems as though this is not possible, but it could really allow for using jinja’s looping function. I realize the with\_items functionality, but I would like to use both at the same time, it would greatly simplify my templates, and was wondering if this was something that is possible another way?

from vars file:  
mgmt\_access\_networks = [‘172.0.0.0.0/24’, ‘172.1.0.0/16’]

when trying to run:  
base\_vars must be stored as dictionary/hash: \<type ‘str’\>

from jijna template:  
{% for item in mgmt\_access\_networks %}  
{{ item }}  
{% endfor %}

what I’m trying to do is loop thru file creation, without having to create a “custom” template for each file. The with\_item functionality seems to get me the loop, but looks as though I can only alter 1 variable per file without access to more jinja functionality.

Thanks,

Greg

---

<div class="post-metadata">

**Author:** ![Dimon](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Dimon](https://forum.ansible.com/u/Dimon)\
**Post date:** [May 6, 2014, 12:18am UTC](https://forum.ansible.com/t/defining-a-list-inside-variable-file-to-allow-for-jinja-loops-for-that-list/15157/2 "2014-05-06T00:18:36Z")

</div>

how about:

mgmt\_access\_networks:

- 172.0.0.0.0/24
- [172.1.0.0/16](http://172.1.0.0/16)

?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 6, 2014, 3:53am UTC](https://forum.ansible.com/t/defining-a-list-inside-variable-file-to-allow-for-jinja-loops-for-that-list/15157/3 "2014-05-06T03:53:45Z")

</div>

"It seems as though this is not possible, but it could really allow for using jinja’s looping function. "

This is entirely possible.

Any of the variables files expept the INI file format inventory file allow this.

group\_vars/groupname being one of the easiest options.

---

<div class="post-metadata">

**Author:** ![greg\_cox](https://avatars.discourse-cdn.com/v4/letter/g/35a633/32.png) [@greg\_cox](https://forum.ansible.com/u/greg_cox)\
**Post date:** [May 6, 2014, 1:03pm UTC](https://forum.ansible.com/t/defining-a-list-inside-variable-file-to-allow-for-jinja-loops-for-that-list/15157/4 "2014-05-06T13:03:36Z")

</div>

I haven’t tried that, I found that I could include entire var files with the playbook(not the task), and then go with layers of dictionaries, that I can reference from Jinja from taht variable file.

Thank you
