return values of dictionary fields using j2

23 views
Skip to first unread message

Dader Grund

unread,
Nov 10, 2016, 9:20:59 AM11/10/16
to Ansible Project
hallo all,

i have  defined following variables in my playbook:
-
vars:
  ip:
     fw1: 0.0.0.1
     fw2: 0.0.0.2

-

temple.j2 contains :

{% for addr in ip %} {{ addr }}  {% endfor %}

# this returns the name of the fields : fw1 fw2

what should i edit in the for loop inoder to return the values of the fields ? namely 0.0.0.1 0.0.0.2

note : using an arrray intead of a dictionary wouldn't help me because i need the ip-value of a specific firewall in another part in the playbook.
 

Kai Stian Olstad

unread,
Nov 10, 2016, 9:32:52 AM11/10/16
to ansible...@googlegroups.com
On 10. nov. 2016 15:20, Dader Grund wrote:
> i have defined following variables in my playbook:
> -
> vars:
> ip:
> fw1: 0.0.0.1
> fw2: 0.0.0.2
>
> -
>
> temple.j2 contains :
>
> {% for addr in ip %} {{ addr }} {% endfor %}
>
> # this returns the name of the fields : fw1 fw2
>
> what should i edit in the for loop inoder to return the values of the
> fields ? namely 0.0.0.1 0.0.0.2

{% for key, value in ip.iteritems() %} {{ value }} {% endfor %}

To read more about it
http://jinja.pocoo.org/docs/dev/templates/#for


--
Kai Stian Olstad

Dader Grund

unread,
Nov 10, 2016, 12:38:11 PM11/10/16
to Ansible Project, ansible-pr...@olstad.com
Thanks alot ^^
Reply all
Reply to author
Forward
0 new messages