Discussion:
[ansible-project] Using dictionary keys as a list in with_items
Mischa ter Smitten
2015-07-30 10:19:36 UTC
Permalink
Thanks for the great tip!

with_items: "{{ databases.keys() }}"

also seems to work, but then you would have no access to the values :-)
Here's and example using the Jinja2's dictsort filter to turn a dictionary
into a list of (key,value) pairs which you can than iterate over with
user: service_app
pass: 'secret'
user: website_app
pass: 'secret'
user: demo1_app
pass: 'secret'
- name: setup database users
postgresql_user: name={{ item.1.user }} password={{ item.1.pass }}
sudo_user: postgres
with_items: databases|dictsort
Hope this helps.
Kal
Kahlil (Kal) Hodgson GPG: C9A02289
Head of Technology (m) +61 (0) 4 2573 0382
DealMax Pty Ltd (w) +61 (0) 3 9008 5281
Suite 1415
401 Docklands Drive
Docklands VIC 3008 Australia
"All parts should go together without forcing. You must remember that
the parts you are reassembling were disassembled by you. Therefore,
if you can't get them together again, there must be a reason. By all
means, do not use a hammer." -- IBM maintenance manual, 1925
--
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-project+***@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/1ac10d2e-fb1f-4a93-8b64-bba575611b86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...