# creating a list in a var file, for use in jijna template?

**URL:** <https://forum.ansible.com/t/creating-a-list-in-a-var-file-for-use-in-jijna-template/15158>\
**Category:** Ansible Project\
**Created:** [May 5, 2014, 2:03pm UTC](https://forum.ansible.com/t/creating-a-list-in-a-var-file-for-use-in-jijna-template/15158 "2014-05-05T14:03:11Z")\
**Posts on this page:** 3\
**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, 2:03pm UTC](https://forum.ansible.com/t/creating-a-list-in-a-var-file-for-use-in-jijna-template/15158/1 "2014-05-05T14:03:11Z")

</div>

I realize strings are only allowed currently it seems, but I am wondering if there is another way to accomplish the same thing.  
This is for file creation, so I realize I can loop thru with with\_items, but then I can only loop on 1 list. With the ability to have lists or dictionaries in var files, I think the options become significantly greater, without any more complication of current abilities.

This is all to create start with a single file, on a single box, but to have many loops, with potential for more then 1 or 2 layers.

ERROR: must be stored as dictionary/hash: \<type ‘str’\>

vars file

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [May 6, 2014, 1:48am UTC](https://forum.ansible.com/t/creating-a-list-in-a-var-file-for-use-in-jijna-template/15158/2 "2014-05-06T01:48:43Z")

</div>

First thing, don’t use item in your for loop, it is reserved for ansible loops and will cause confusion.

What is base\_vars? how does it get loaded?if it were a yaml file you can do it 2 ways:

mgmt\_access\_networks: [‘[172.22.161.0/24](http://172.22.161.0/24)’, ‘[172.27.0.0/16](http://172.27.0.0/16)’, ‘[172.28.0.0/16](http://172.28.0.0/16)’, ‘[198.18.0.0/15](http://198.18.0.0/15)’]

or

mgmt\_access\_networks:

- '[172.22.161.0/24](http://172.22.161.0/24)

- ‘[172.27.0.0/16](http://172.27.0.0/16)’ … etc

Brian Coca

---

<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:57am UTC](https://forum.ansible.com/t/creating-a-list-in-a-var-file-for-use-in-jijna-template/15158/3 "2014-05-06T03:57:34Z")

</div>

" realize strings are only allowed currently it seems, "

This is not correct.

Variables files, such as group\_vars/groupname, host\_vars/hostname, anything loaded with vars\_files or “include\_vars” can be YAML or JSON, we prefer YAML, and it can be structured and typed.
