Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json Ansible-注册变量,然后搜索变量以设置_事实(Cisco Aci)_Json_Search_Ansible_Cisco_Azure Container Instances - Fatal编程技术网

Json Ansible-注册变量,然后搜索变量以设置_事实(Cisco Aci)

Json Ansible-注册变量,然后搜索变量以设置_事实(Cisco Aci),json,search,ansible,cisco,azure-container-instances,Json,Search,Ansible,Cisco,Azure Container Instances,我查询Cisco ACI以获得特定EPG的高级vmm提供程序详细信息。 结果是成功的。 然后我将结果注册到一个变量。 我尝试搜索该变量并获取\提取单个特定信息,如“dn”或“encap”,因为这将允许我在其他重头戏中使用该信息 不幸的是,我无法提取信息,因为结果以通常的格式返回。查看register变量上的调试,它似乎是一个dictionary变量,但无论我尝试什么,我唯一能够访问的项是“current”项。 所有其他项均未注册为字典项 我试图将变量更改为列表,但仍然无法获得所需的信息。 我搜索

我查询Cisco ACI以获得特定EPG的高级vmm提供程序详细信息。 结果是成功的。 然后我将结果注册到一个变量。 我尝试搜索该变量并获取\提取单个特定信息,如“dn”或“encap”,因为这将允许我在其他重头戏中使用该信息

不幸的是,我无法提取信息,因为结果以通常的格式返回。查看register变量上的调试,它似乎是一个dictionary变量,但无论我尝试什么,我唯一能够访问的项是“current”项。 所有其他项均未注册为字典项

我试图将变量更改为列表,但仍然无法获得所需的信息。 我搜索了论坛,看看是否有一种方法可以将变量从json结果或字典变量转换为字符串,然后grep获取信息,但没有成功。 理想情况下,我希望在不安装其他“应用程序”的情况下提取信息

如果有人能建议如何从一个不规则的嵌套结果中搜索特定的结果,而该结果没有以正确的字典格式列出项目,我们将不胜感激

- name: Access VMM provider Information
  hosts: apics
  gather_facts: false
  connection: local
# # # # DVS_结果
使用json_查询。比如说

- debug:
    msg: "{{ DVS_Result.current|
             json_query('[].fvRsDomAtt.attributes.dn') }}"
  tasks:

     - name: Play 1 Obtain VMM Provider Information
       aci_epg_to_domain:
        hostname: "{{ apics.hostname }}"
        username: "{{ apics.username }}"
        password: "{{ apics.password }}"
        tenant: Tenant_A
        ap: AP_Test
        epg: EPG_Test
        domain: DVS_Dell
        domain_type: vmm
        vm_provider: vmware
        state: query
        validate_certs: no
       register: DVS_Result
     - set_fact:
        aci_result1: "{{ DVS_Result.current }}"

     - set_fact:
        aci_result2: "{{ DVS_Result.fvRsDomAtt.attributes.dn }}"
     - debug:
         msg: "{{ DVS_Result }}"

     - debug:
         var=aci_result1

     - debug:
         var=aci_result2             

ok: [apic1r] => {
    "msg": {
        "changed": false,
        "current": [
            {
                "fvRsDomAtt": {
                    "attributes": {
                        "annotation": "",
                        "bindingType": "none",
                        "childAction": "",
                        "classPref": "encap",
                        "configIssues": "",
                        "delimiter": "",
                        "dn": "uni/tn-TN_prod/ap-AP_Test/epg-EPG_Test/rsdomAtt-[uni/vmmp-VMware/dom-DVS_Dell]",
                        "encap": "unknown",
                        "encapMode": "auto",
                        "epgCos": "Cos0",
                        "epgCosPref": "disabled",
                        "extMngdBy": "",
                        "forceResolve": "yes",
                        "instrImedcy": "lazy",
                        "lagPolicyName": "",
                        "lcOwn": "local",
                        "modTs": "2019-08-18T20:52:13.570+00:00",
                        "mode": "default",
                        "monPolDn": "uni/tn-common/monepg-default",
                        "netflowDir": "both",
                        "netflowPref": "disabled",
                        "numPorts": "0",
                        "portAllocation": "none",
                        "primaryEncap": "unknown",
                        "primaryEncapInner": "unknown",
                        "rType": "mo",
                        "resImedcy": "lazy",
                        "secondaryEncapInner": "unknown",
                        "state": "missing-target",
                        "stateQual": "none",
                        "status": "",
                        "switchingMode": "native",
                        "tCl": "infraDomP",
                        "tDn": "uni/vmmp-VMware/dom-DVS_Dell",
                        "tType": "mo",
                        "triggerSt": "triggerable",
                        "txId": "8646911284551354729",
                        "uid": "15374"
                    }
                }
            }
        ],
        "failed": false
    }
}

######################################


### aci_result1


ok: [apic1r] => {
    "aci_result1": [
        {
            "fvRsDomAtt": {
                "attributes": {
                    "annotation": "",
                    "bindingType": "none",
                    "childAction": "",
                    "classPref": "encap",
                    "configIssues": "",
                    "delimiter": "",
                    "dn": "uni/tn-TN_prod/ap-AP_Test/epg-EPG_Test/rsdomAtt-[uni/vmmp-VMware/dom-DVS_Dell]",
                    "encap": "unknown",
                    "encapMode": "auto",
                    "epgCos": "Cos0",
                    "epgCosPref": "disabled",
                    "extMngdBy": "",
                    "forceResolve": "yes",
                    "instrImedcy": "lazy",
                    "lagPolicyName": "",
                    "lcOwn": "local",
                    "modTs": "2019-08-18T20:52:13.570+00:00",
                    "mode": "default",
                    "monPolDn": "uni/tn-common/monepg-default",
                    "netflowDir": "both",
                    "netflowPref": "disabled",
                    "numPorts": "0",
                    "portAllocation": "none",
                    "primaryEncap": "unknown",
                    "primaryEncapInner": "unknown",
                    "rType": "mo",
                    "resImedcy": "lazy",
                    "secondaryEncapInner": "unknown",
                    "state": "missing-target",
                    "stateQual": "none",
                    "status": "",
                    "switchingMode": "native",
                    "tCl": "infraDomP",
                    "tDn": "uni/vmmp-VMware/dom-DVS_Dell",
                    "tType": "mo",
                    "triggerSt": "triggerable",
                    "txId": "8646911284551354729",
                    "uid": "15374"
                }
            }
        }
    ]
}




############################################

### aci_result2

fatal: [apic1r]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'fvRsDomAtt'\n\nThe error appears to be in '/etc/ansible/playbooks/cisco/aci/create_bd_ap_epg3.yml': line 37, column 8, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n     - set_fact:\n       ^ here\n"}

- debug:
    msg: "{{ DVS_Result.current|
             json_query('[].fvRsDomAtt.attributes.dn') }}"