我有一个查询返回:
ok: [oc-ar-ar-test-ansible-api] => {
"ivr_list.json": [
{
"announcement": {
"id": "0",
"name": "None"
},
"dests": {
"i": {
"id": "101",
"name": "Pablo Gonzalez",
"type": "Extension"
},
"t": {
"id": "100",
"name": "Fruta Peralta",
"type": "Extension"
}
},
"id": "3",
"loops": "2",
"name": "Prueba",
"timeout": "10"
},
{
"announcement": {
"id": "8",
"name": "General-ES"
},
"dests": {
"i": {
"id": "10000",
"name": "General",
"type": "Queue"
},
"t": {
"id": "10000",
"name": "General",
"type": "Queue"
}
},
"id": "23",
"loops": "2",
"name": "General-ES",
"timeout": "10"
}
]
}
我需要根据 IVR 名称获取“id”。例如:
如果IVR名称为“General-ES”,则必须返回“id”23。
你能帮我解决这个问题吗,我还没有找到办法?
我做了很多测试,但我做不到,要么无论我输入什么名字,它总是返回一个ID,要么我什么也没得到。
非常感谢您的回复,帮我解决了问题。 在这里,我留下了解决该问题的代码行。
- name: test1
debug:
msg: "{{ ivr_list.json | json_query(jmesquery) | selectattr('Name', 'equalto', 'General-ES') | map(attribute='Id') | list }}"
vars:
jmesquery: "[*].{Name: name, Id: id}"
register: ivr_filter_id
tags:
- test