Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/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
使用Ansible中大括号内的键访问项的dict值_Ansible_Yaml_Saml - Fatal编程技术网

使用Ansible中大括号内的键访问项的dict值

使用Ansible中大括号内的键访问项的dict值,ansible,yaml,saml,Ansible,Yaml,Saml,由于dict具有非常奇怪的密钥,因此在访问dict的值时遇到问题。我使用xml模块过滤名称空间来设置这个对象,然后设置一个等于返回的匹配值的事实。如果有更好/更简单的方法,我会喜欢的,因为我被难倒了 XML示例: <md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" entityID="http://www.okta.com/id"> <md:ID

由于dict具有非常奇怪的密钥,因此在访问dict的值时遇到问题。我使用xml模块过滤名称空间来设置这个对象,然后设置一个等于返回的匹配值的事实。如果有更好/更简单的方法,我会喜欢的,因为我被难倒了

XML示例:

<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" entityID="http://www.okta.com/id">
    <md:IDPSSODescriptor WantAuthnRequestsSigned="false"
        protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
        <md:KeyDescriptor use="signing">
            <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                <ds:X509Data>
                    <ds:X509Certificate>thisisfakedata</ds:X509Certificate>
                </ds:X509Data>
            </ds:KeyInfo>
        </md:KeyDescriptor>
        <md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress</md:NameIDFormat>
        <md:NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</md:NameIDFormat>
        <md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
            Location="https://login.company.com/app/app/id/sso/saml" />
        <md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
            Location="https://login.company.com/app/app/id/sso/saml" />
    </md:IDPSSODescriptor>
</md:EntityDescriptor>
注册结果如下所示:

{
    "actions": {
        "namespaces": {
            "x": "urn:oasis:names:tc:SAML:2.0:metadata",
            "y": "http://www.w3.org/2000/09/xmldsig#"
        },
        "state": "present",
        "xpath": "/x:EntityDescriptor/x:IDPSSODescriptor/x:KeyDescriptor/y:KeyInfo/y:X509Data/y:X509Certificate"
    },
    "changed": false,
    "count": 1,
    "matches": [{
        "{http://www.w3.org/2000/09/xmldsig#}X509Certificate": "thisisfakedata"
    }],
    "msg": 1,
    "xmlstring": "seexml"
}
如果我在匹配列表中尝试将一个事实设置为该键的值,它将不起作用。我尝试了很多方法,最近设置了一个等于obj.matches[0]的事实,然后尝试只打印“{fact”{http://www.w3.org/2000/09/xmldsig#}X509Certificate}“我遇到了问题。请参阅下面的错误。我能做些什么来实现这一点,或者转义它们的密钥以使其正常工作,或者改变我对xml模块的使用以获得更正常的密钥?我正试图避免把它弄得比现在更糟

- name: "set idp cert"
  set_fact:
    idp_app_cert: "{{ xml_xpath_result.matches[0] }}"
  when: xml_xpath_result is defined

- debug:
    msg: "{{ idp_app_cert.{http://www.w3.org/2000/09/xmldsig#}X509Certificate }}"
错误:

TASK [pbname : debug] ********************************************************************************************************************
task path: ~tasks/main.yml:40
fatal: [localhost]: FAILED! => {"msg": "template error while templating string: expected name or number. String: {{ idp_app_cert.{http://www.w3.org/2000/09/xmldsig#}X509Certificate }}"}

为了清楚起见,这里的最终结果只是用值设置了一个事实:thisisfakedata通过不同方式访问我的密钥,并在其周围添加单引号,从而绕过了这个问题。留着这个,以防其他人遇到类似的情况

- debug:
    msg: "{{ idp_app_cert['{http://www.w3.org/2000/09/xmldsig#}X509Certificate'] }}"

你试过这个语法吗{{idp_应用程序_证书[{}X509Certificate']}
- debug:
    msg: "{{ idp_app_cert['{http://www.w3.org/2000/09/xmldsig#}X509Certificate'] }}"
TASK [pbname : debug] ********************************************************************************************************************
task path: ~/tasks/main.yml:40
ok: [localhost] => {
    "msg": "thisisfakedata"
}