On 27.08.2019 21:44, Cade Lambert wrote: > I'm trying to register the value of a JSON object only when another JSON > object is equal to a certain value, but I just can't figure out how I'd do > that. > > For example, this is my JSON output which is registered in the variable > results_var: > > "output": { > "json": { > "results": [ > { > "name": "item1" > "id": "26" > } > { > "name": "item2" > "id": "29" > } > { > "name": "item3" > "id": "10" > } > ] > } > }
This output looks wired, it's missing commas after } in the list. > What I'd like to do is place the id into a variable only when the name > matches a string. > > I was trying something like this but it fails because the variable is a > list. > > - set_fact: > host_id: "{{ item.id }}" > when: item.name == "item2" > loop: "{{ results_var.output.json.results }}" You should always provide the exact error message and probably the all the code too, at fist glance I don't see anything wrong with the code. -- Kai Stian Olstad -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2d1b222c-a02c-f436-a15f-3c822bb30f1a%40olstad.com.