Hello - I have a question about looping over json data I’ve received from calling a REST api using the URI module. I’ve been tearing my hair out over the last several days trying to sort this out…and have googled extensively - but haven’t gotten anywhere. I think it has to do with the difference between a dict, and array, and a list…but i’m new-ish to ansible and not understanding what i’m doing wrong. Any help greatly appreciated.
Here is the data returned and registered by the URI module call. Lets say I registered it in a variable called "registered_variable" https://gist.github.com/andris/77dcdfd17eef0cdd3563 I can access individual items from the array by doing this: registered_variable.json.data[1] I can access attributes of individual items from the array by doing this: registered_variable.json.data[1].name But whenever I try to use with_dict or with_items to loop over registered_variable.json.data....I just get an "item is undefined error" (for example) - debug: msg: "{{item.name}} is the name of the device" with_dict: "{{registered_variable.json.data}}" I also tried first storing the object in a variable first: - set_fact: devices: "{{ registered_variable.json.data }}" - debug: msg: "{{item.name}} is the device name" with_dict: devices I am running on the latest dev from checkout (2.0.0) Any suggestions? Thanks in advance! -- 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/1ac36d0b-5a45-45df-b89e-588c2059aa71%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
