ansible.builtin.intersect filter – intersection of lists
Note
This filter plugin is part of ansible-core
and included in all Ansible
installations. In most cases, you can use the short
plugin name
intersect
even without specifying the collections:
keyword.
However, we recommend you use the FQCN for easy linking to the
plugin documentation and to avoid conflicting with other collections that may have
the same filter plugin name.
New in Ansible 1.4
Synopsis
Provide a list with the common elements from other lists.
Input
This describes the input of the filter, the value before | ansible.builtin.intersect
.
Parameter |
Comments |
---|---|
A list. |
Keyword parameters
This describes keyword parameters of the filter. These are the values key1=value1
, key2=value2
and so on in the following example: input | ansible.builtin.intersect(key1=value1, key2=value2, ...)
.
Parameter |
Comments |
---|---|
A list. |
See Also
See also
- ansible.builtin.difference filter plugin
The official documentation on the ansible.builtin.difference filter plugin.
- ansible.builtin.symmetric_difference filter plugin
The official documentation on the ansible.builtin.symmetric_difference filter plugin.
- ansible.builtin.unique filter plugin
The official documentation on the ansible.builtin.unique filter plugin.
- ansible.builtin.union filter plugin
The official documentation on the ansible.builtin.union filter plugin.
Examples
# return only the common elements of list1 and list2
# list1: [1, 2, 5, 3, 4, 10]
# list2: [1, 2, 3, 4, 5, 11, 99]
{{ list1 | intersect(list2) }}
# => [1, 2, 5, 3, 4]
Return Value
Key |
Description |
---|---|
A list with unique elements common to both lists, also known as a set. Returned: success |