Skip to content

contains

Collection Note

This module is part of the ansible.builtin collection. To install the collection, use:

ansible-galaxy collection install ansible.builtin
Added in version 2.4.

Synopsis

  • Checks the supplied element against the input list to see if it exists within it.

Parameters

Parameter Defaults / Choices Comments
_contained
raw
required
Element to test for.
_input
list / elements=raw
required
List of elements to compare.

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 Values

Key Data Type Description Returned
_value boolean Returns V(True) if the specified element is contained in the supplied sequence, V(False) otherwise.

Authors

  • Ansible Core