community.general.lists_difference 过滤器 – 带有预测顺序的列表差异
注意
此过滤器插件是 community.general 集合(版本 10.1.0)的一部分。
如果您使用的是 ansible
包,您可能已经安装了这个集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install community.general
。
要在 playbook 中使用它,请指定:community.general.lists_difference
。
community.general 8.4.0 中的新增功能
概要
提供第一个列表中所有未出现在其他列表中的元素的唯一列表。
结果列表中项目的顺序将保留。
输入
这描述了过滤器的输入,即 | community.general.lists_difference
之前的值。
参数 |
注释 |
---|---|
一个列表。 |
关键字参数
这描述了过滤器的关键字参数。这些是以下示例中 key1=value1
、key2=value2
等值:input | community.general.lists_difference(key1=value1, key2=value2, ...)
参数 |
注释 |
---|---|
是否从输入列表中删除一个层次结构级别。 选项
|
示例
- name: Return the difference of list1 and list2.
ansible.builtin.debug:
msg: "{{ list1 | community.general.lists_difference(list2) }}"
vars:
list1: [1, 2, 5, 3, 4, 10]
list2: [1, 2, 3, 4, 5, 11, 99]
# => [10]
- name: Return the difference of list1, list2 and list3.
ansible.builtin.debug:
msg: "{{ [list1, list2, list3] | community.general.lists_difference(flatten=true) }}"
vars:
list1: [1, 2, 5, 3, 4, 10]
list2: [1, 2, 3, 4, 5, 11, 99]
list3: [1, 2, 3, 4, 5, 10, 99, 101]
# => []
返回值
键 |
描述 |
---|---|
第一个列表中所有未出现在其他列表中的元素的唯一列表。 已返回: 成功 |