Ansible loop over JSON output from URI Call Ansible loop over JSON output from URI Call json json

Ansible loop over JSON output from URI Call


Try:

- debug: msg="{{ item.host_name }} {{ item.component_name }}"  with_items: "{{ list_of_components.results | map(attribute='content') | map('from_json') | map(attribute='host_components') | sum(start=[]) | map(attribute='HostRoles') | list }}"

Code is not tested!

The idea is: take list_of_components.results, take only content out of it, apply from_json filter, take only host_components list out of it, flatten list of components lists into single list with sum, take HostRoles out of it, cast to list (from map result).

So this code should give you a list of this kind of items:

{    "cluster_name" : "pstl-cluster",    "component_name" : "METRICS_MONITOR",    "host_name" : "slave2.mycluster"}