ansible.builtin.search test – Does string match a regular expression

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 search 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 test plugin name.

Synopsis

  • Compare string against regular expression using Python’s search function.

Input

This describes the input of the test, the value before is ansible.builtin.search or is not ansible.builtin.search.

Parameter

Comments

Input

string / required

String to match.

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.search(key1=value1, key2=value2, ...) and input is not ansible.builtin.search(key1=value1, key2=value2, ...).

Parameter

Comments

ignorecase

boolean

Use case insenstive matching.

Choices:

  • false ← (default)

  • true

multiline

boolean

Match against mulitple lines in string.

Choices:

  • false ← (default)

  • true

pattern

string / required

Regex to match against.

Examples

url: "https://example.com/users/foo/resources/bar"
foundmatch: url is search("https://example.com/users/.*/resources")
alsomatch: url is search("users/.*/resources")

Return Value

Key

Description

Return value

boolean

Returns True if there is a match, False otherwise.

Returned: success

Authors

  • Ansible Core

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.