Hello all, I'm struggling to find a way to use *[] inside a query to traverse an Ansible variable. The content of the variable comes from a JSON file. The error message I get is "*template error while templating string: expected name or number. String: {{ result.root.*[].component }}*".
Let's say the variable (result) contains the following JSON content: { "root": { "DEV": [ { "component": { "artifactId": "component-1", "version": "1.0.0" } } ], "STG": [ { "component": { "artifactId": "component-2", "version": "1.0.1" }, "runtimeConf": { "artifactId": "runtime-configuration", "version": "1.0.1" } } ] } } My Ansible code tries to extract the values of all the *"component"* attributes as a list, regardless of the external attributes where the *"component"* attributes are defined (in the example, *"DEV"* and "STG"). These external attributes are not known beforehand, hence the need for that *[] in the query. tasks: - set_fact: component_list: "{{ result.root.*[].component }}" The output I expect is: [ { "artifactId": "component-1" "version": "1.0.0" }, { "artifactId": "component-2", "version": "1.0.1" } ] That is, a list of all the objects whose attribute was *"component"* in the input JSON. I've tried to execute the same query on the JMESPath website <http://jmespath.org/> with the same input and the result is the one I expect. Unfortunately, this is not the case while executing the task with Ansible. Am I doing something wrong here? Thanks in advance for your help. -- 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+unsubscr...@googlegroups.com. To post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d711a186-f17c-49c1-8e18-176003ed29cc%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.