Looping over a hash Subelement

39 views
Skip to first unread message

Luis Óscar Ramos Carreón

unread,
Sep 25, 2015, 12:54:40 PM9/25/15
to Ansible Project
Hi,

I would like to do something like the example in Looping over Subelements but using a hash instead of a list.

---
users
:
 demo
:
   name
: alice
   authorized
:
 
- /tmp/alice/onekey.pub
 
- /tmp/alice/twokey.pub
 admin
:
 name
: bob
 authorized
:
 
- /tmp/bob/id_rsa.pub

I couldn't make it work. Is it even possible? Is there any alternative to loop over a hash subelements?

I'm using a hash because in other tasks I need to use an specific item value: {{ users.demo.name }}

Thank you for your time.

Serge van Ginderachter

unread,
Sep 25, 2015, 12:57:25 PM9/25/15
to ansible...@googlegroups.com
Can you show the task how you try that?

--
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/1c16fc38-fdd9-4d5e-854b-de9b03ad51bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luis Óscar Ramos Carreón

unread,
Sep 25, 2015, 2:48:18 PM9/25/15
to Ansible Project
I was trying to follow with_dic notation,

- command: echo {{ item.0.value.name }} {{ item.1 }}
  with_subelements
:
   
- users
   
- authorized

but then I just used directly the name property and it worked:

- command: echo {{ item.0.name }} {{ item.1 }}
  with_subelements
:
   
- users
   
- authorized


I apologize for wasting your time.
Reply all
Reply to author
Forward
0 new messages