问题
I am trying to extract few values from a task out put.
please see my playbook sample
- name: Iterate JSON
set_fact:
app_item: "{{ item.name }}"
when: "{{ result.results|json_query('[].\"scope member\"[?\"vdom\"==`\"vdom-shop\"`].vdom')|flatten|first }} == vdom-shop"
with_items: "{{ result.results }}"
please see the json output from the previous task
{
"msg": {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"failed": false,
"msg": "Custom Query Success",
"results": [
{
"name": "FG-04-Policy",
"obj ver": 3,
"oid": 1196,
"package settings": {
"central-nat": "disable",
"fwpolicy-implicit-log": "disable",
"fwpolicy6-implicit-log": "disable",
"inspection-mode": "proxy"
},
"scope member": [
{
"name": "IN-FG-04",
"vdom": "vdom-shop"
}
],
"type": "pkg"
},
{
"name": "FG-04-DC",
"obj ver": 23,
"oid": 1216,
"package settings": {
"central-nat": "disable",
"fwpolicy-implicit-log": "disable",
"fwpolicy6-implicit-log": "disable",
"inspection-mode": "proxy"
},
"scope member": [
{
"name": "IN-FG-04",
"vdom": "vdom1-dc"
}
],
"type": "pkg"
}
]
}
}
the expected out put should be like below with following condition.
"name": "FG-04-Policy" when "vdom"== "vdom-shop"
"name": "FG-04-DC" when "vdom"== "vdom1-dc"
Basically i wanted to extract "FG-04-Policy" when the condition is matching from the above example i am expecting name as FG-04-Policy when the vdom value equal to vdom-shop
Can some one help me here
来源:https://stackoverflow.com/questions/56215022/how-to-set-ansible-conditinal-search