dict in dict access value in with_item

31 views
Skip to first unread message

Pierre Mavro

unread,
Nov 7, 2015, 8:48:05 AM11/7/15
to Ansible Project
Hi,

I've got a dict in dict in a var file. When debuging this var, it looks like this:

    "var": {
       
"nm_java_apps_params": {
           
"nm-core": {
               
"dest_folder": '/tmp/test'
               
"port": 9487,
               
"start_options": " -Xmx16G -XX:+UseG1GC -XX:+UseStringDeduplication",
               
"version": "latest"
           
},
           
"nm-staticmaps": {
                "dest_folder": '/tmp/test'
               
"port": 9462,
               
"start_options": "",
               
"war_name": "latest.war"
           
}
       
}
   
}

I would like to be able to use those vars in a role with a with_item statement. Here is what it looks like:

- name: create operation folder
  file
: path="{{item}}" owner=user mode=0755 state=directory
  with_items
:
   
- nm_java_apps_params["{{another_var_here}}"]['dest_folder']

But I can't get it correctly resolved. Here is what I got:

TASK: [nm.java-apps | create operation folder] ********************************

changed
: [x.x.x.x] => (item=nm_java_apps_params["my_var"]['dest_folder'])

In fact it creates a folder named: "nm_java_apps_params["my_var"]['dest_folder']", which is of course what I'm not really expecting. I thought having '/tmp/test' instead.

Any ideas on how I can resolve this problem ?

Thanks

Alex Leonhardt

unread,
Nov 7, 2015, 9:17:33 AM11/7/15
to ansible...@googlegroups.com

I think you need 'with_nested' here?
http://docs.ansible.com/ansible/playbooks_loops.html

Alex

--
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/eebc8ab0-3e82-435a-bcdd-d14535a640cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pierre Mavro

unread,
Nov 7, 2015, 9:47:16 AM11/7/15
to Ansible Project
It works ! Thanks !
Reply all
Reply to author
Forward
0 new messages