【发布时间】:2020-08-12 13:44:21
【问题描述】:
我有两个列表:
list1:
- file: f1
perm: '777'
- file: f2
perm: '677'
- file: f3
perm: '755'
- file: f4
perm: '700'
list2:
- file: f4
t_perm: '755'
- file: f3
t_perm: '677'
- file: f10
t_perm: '777'
我必须将它们合并到如下的新列表中:
list3:
- file: f1
perm: '777'
- file: f2
perm: '677'
- file: f3
perm: '755'
t_perm: '677'
- file: f4
perm: '700'
t_perm: '755'
正常的合并是由
完成的 - set_fact:
list3: "{{ (list1 + list2)|
groupby('file')|
map('last')|
map('combine')|
list }}"
但我还有一个条件。如果文件存在于 list1 中而不存在于 list2 中,则合并。如果文件存在于 list2 中而不存在于 list1 中,则不要合并,忽略它。
【问题讨论】:
-
我已经更新了。