我正在尝试通过Ansible从Keycloak安装中获取RSA密钥。我从Keycloak API返回的变量是:
"msg": {
"cache_control": "no-cache",
"changed": false,
"connection": "close",
"content_length": "2011",
"content_type": "application/json",
"cookies": {},
"cookies_string": "",
"date": "Sun, 05 Jul 2020 13:32:42 GMT",
"elapsed": 0,
"failed": false,
"json": {
"active": {
"AES": "redactedredactedredacted-redacted-redacted",
"HS256": "redactedredactedredacted-redacted-redacted",
"RS256": "redactedredactedredacted-redacted-redacted"
},
"keys": [
{
"algorithm": "HS256",
"kid": "redactedredactedredacted-redacted-redacted",
"providerId": "redactedredactedredacted-redacted-redacted",
"providerPriority": 100,
"status": "ACTIVE",
"type": "OCT"
},
{
"algorithm": "AES",
"kid": "redactedredactedredacted-redacted-redacted",
"providerId": "redactedredactedredacted-redacted-redacted",
"providerPriority": 100,
"status": "ACTIVE",
"type": "OCT"
},
{
"algorithm": "RS256",
"certificate": "redactedredactedredacted-redacted-redactedredactedredactedredacted-redacted-redactedredactedredactedredacted-redacted-redactedredactedredactedredacted-redacted-redactedredactedredactedredacted-redacted-redactedredactedredactedredacted-redacted-redactedredactedredactedredacted-redacted-redactedredactedredactedredacted-redacted-redactedredactedredactedredacted-redacted-redactedredactedredactedredacted-redacted-redactedredactedredactedredacted-redacted-redactedredactedredactedredacted-redacted-redacted=",
"kid": "redactedredactedredacted-redacted-redacted",
"providerId": "redactedredactedredacted-redacted-redacted",
"providerPriority": 100,
"publicKey": "thisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEY",
"status": "ACTIVE",
"type": "RSA"
}
]
},
"msg": "OK (2011 bytes)",
"redirected": false,
"status": 200,
"strict_transport_security": "max-age=31536000; includeSubDomains",
"url": "http://localhost:8080/auth/admin/realms/master/keys",
"x_content_type_options": "nosniff",
"x_frame_options": "SAMEORIGIN",
"x_xss_protection": "1; mode=block"
}
}
...我希望publicKey生成一个JWK。可以说我正在使用kc_keys
API响应对象中的变量。
"{{ kc_keys.json['keys'] | map(attribute='publicKey') }}"
...返回"msg": "<generator object do_map at 0x7f9c6b3014d0>"
。
好的,这是一个对象。我可以将其转换为"{{ kc_keys.json['keys'] | map(attribute='publicKey') | list }}"
返回的列表...
"msg": "[AnsibleUndefined, AnsibleUndefined, 'thisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEYthisISApublicKEY']"
从这里开始,文档尚不清楚我如何将我自己提取thisISApublicKEY...
为字符串。如何从上面的最后一步中获取字符串中的列表中的最后一个元素?
如果您只是在寻找publicKey
这个简单的json_query过滤器就可以。
- debug:
msg: "{{ kc_keys.json | json_query('*[].publicKey') }}"
替代
- debug:
msg: "{{ kc_keys.json['keys'] | selectattr('publicKey', 'defined') | map(attribute='publicKey') | list }}"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句