我有以下列表:
"list_stores": [
{
"aliases": [],
"expiry": [],
"path": "/path/to/keystore1.jks"
},
{
"aliases": [
"abc"
],
"expiry": [
"Certificate will not expire"
],
"path": "/path/to/keystore2.jks"
},
{
"aliases": [
"1194",
"1195",
"1196"
],
"expiry": [
"Certificate will not expire",
"Certificate will not expire",
"Certificate will expire"
],
"path": "/path/to/keystore3.jks"
}]
我想创建一个具有类似dict的列表(省略“别名”和“到期”的空列表):
"final_list": [
{
"path": "/path/to/keystore2.jks",
"result": [
{
"alias": "abc",
"expiry": "Certificate will not expire"
}
]
},
{
"path": "/path/to/keystore3.jks",
"result": [
{
"alias": "1194",
"expiry": "Certificate will not expire"
},
{
"alias": "1195",
"expiry": "Certificate will not expire"
},
{
"alias": "1196",
"expiry": "Certificate will expire"
}
]
}]
首先,我尝试通过映射属性“别名”和“过期”来创建新列表:
- name: Set fact list_aliases
set_fact:
list_aliases: "{{ list_store_alias_validity | map(attribute='aliases') | list }}"
这将导致有两个新列表。我尝试压缩它们,但仍然必须包含'path'属性。我该如何解决?