I've hit this before, The problem is, sometimes it's nice to have a list to loop over especially if the client code doesn't know the keys. Other times it would be nice to have a dict if you have the key since writing loops can be messy.
I think it would be very nice in these cases to have a dict_to_list adapter and list_to_dict adapter as jinja2 plugins, so the original datastructure can be whichever. I got started on this but never finished. https://gist.github.com/7a2109be1f0006bae89a.git On Friday, June 27, 2014 4:24:11 AM UTC-5, Tomasz Kontusz wrote: > > > > jepper <[email protected] <javascript:>> napisał: > > > > > >I have the following defined in vars or defaults: > > > >fusemq_authentication: > >- { 'username':'admin', 'password’:'blah', 'groups':'admin' > >} > > - { 'username':'LOGSTASH', 'password’:'bing', 'groups':'LOGSTASH' } > This should be a dictionary > > >I want to know the password for LOGSTASH in a template. Today I loop > >until > >I find it. Is there a simpler way? > > > >{% for value in fusemq_authentication %} > >{% if value.username=="LOGSTASH" %} > >fuseMQ_password={{ value.password }} > >{% endif %} > >{% endfor %} > Yes, with fusemq_authentication as a dict it would be: > fuseMQ_password={{ fusemq_authentication. LOGSTASH.password }} > -- > Wysłane za pomocą K-9 Mail. > -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/329f568f-ff2f-427d-9151-6f00950a99da%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
