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

546 views
Skip to first unread message

greg cox

unread,
May 5, 2014, 9:27:57 AM5/5/14
to ansible...@googlegroups.com
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

Dmitry Makovey

unread,
May 5, 2014, 8:18:36 PM5/5/14
to ansible...@googlegroups.com


On Monday, May 5, 2014 7:27:57 AM UTC-6, greg cox wrote:
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']

how about:

mgmt_access_networks:
- 172.0.0.0.0/24
 
?

Michael DeHaan

unread,
May 5, 2014, 11:53:45 PM5/5/14
to ansible...@googlegroups.com
"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.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6ef7ab91-e9d6-4e4f-832c-3b9caf2140ad%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

greg cox

unread,
May 6, 2014, 9:03:36 AM5/6/14
to ansible...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages