how to set ansible conditinal search

自作多情 提交于 2020-01-06 08:03:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!