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

736 views
Skip to first unread message

greg cox

unread,
May 5, 2014, 10:03:11 AM5/5/14
to ansible...@googlegroups.com
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
---
# file: files/base_vars
mgmt_access_networks = ['172.22.161.0/24', '172.27.0.0/16', '172.28.0.0/16', '198.18.0.0/15']


Jinja template:
{% for item in mgmt_access_networks %}
{{ item }}
{% endfor %}


Brian Coca

unread,
May 5, 2014, 9:48:43 PM5/5/14
to ansible...@googlegroups.com

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', '172.27.0.0/16', '172.28.0.0/16', '198.18.0.0/15']

or 

mgmt_access_networks:

      - '172.22.161.0/24

      - '172.27.0.0/16' ... etc


Brian Coca

Michael DeHaan

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





--
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/CADn%2BHsym5C4EidkF9Bwv5cigvOjyoRtZypMk-ibJX9qbbKd_YA%40mail.gmail.com.

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

Reply all
Reply to author
Forward
0 new messages