ansible.builtin.contains test – does the list contain this element
Note
This test plugin is part of ansible-core and included in all Ansible installations. In most cases, you can use the short plugin name contains. However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.contains for easy linking to the plugin documentation and to avoid conflicting with other collections that may have the same test plugin name.
Synopsis
- Checks the supplied element against the input list to see if it exists within it.
Input
This describes the input of the test, the value before is ansible.builtin.contains or is not ansible.builtin.contains.
Parameter | Comments |
|---|---|
Input list / elements=any / required | List of elements to compare. |
Keyword parameters
This describes keyword parameters of the test. These are the values key1=value1, key2=value2 and so on in the following examples: input is ansible.builtin.contains(key1=value1, key2=value2, ...) and input is not ansible.builtin.contains(key1=value1, key2=value2, ...)
Parameter | Comments |
|---|---|
_contained any / required | Element to test for. |
Examples
# simple expression
{{ listofthings is contains('this') }}
# as a selector
- action: module=doessomething
when: (lacp_groups|selectattr('interfaces', 'contains', 'em1')|first).master
vars:
lacp_groups:
- master: lacp0
network: 10.65.100.0/24
gateway: 10.65.100.1
dns4:
- 10.65.100.10
- 10.65.100.11
interfaces:
- em1
- em2
- master: lacp1
network: 10.65.120.0/24
gateway: 10.65.120.1
dns4:
- 10.65.100.10
- 10.65.100.11
interfaces:
- em3
- em4
Return Value
Key | Description |
|---|---|
Return value boolean | Returns Returned: success |
Collection links
© 2012–2018 Michael DeHaan
© 2018–2025 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/contains_test.html