I'm trying to get the value of an attribute in a json array with Ansible. Example data:
"domains.json.data": [
{
"axfr_ips": [],
"description": "",
"domain": "mydomain.net",
"expire_sec": 0,
"group": "",
"id": 687088,
},
{
"axfr_ips": [],
"description": "",
"domain": "myotherdomain.net",
"expire_sec": 0,
"group": "",
"id": 687089,
}
]
}
So I tried with json query:
"{{ domains.json.data | json_query(\"data[?domain=='{{ server_domain }}'].id\") }}"
or with:
- set_fact:
domain_id: "{{ domains | json_query(query) | first }}"
vars:
query: "domains.json[?name=='{{ server_domain }}'].id"
Also tried with selectattrib:
"{{ linode_domains.json.data | selectattr(\"domain\", \"{{ server_domain }}\") | list }}"
So what I need is to get the id of the domain I got in {{ server_domain }}.
["mydomain.net", "myotherdomain.net"]?