mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Adds search/match examples to "Playbooks > Variables > Jinja2 Filters" doc section.
This commit is contained in:
@@ -291,6 +291,18 @@ doesn't know it is a boolean value::
|
||||
- debug: msg=test
|
||||
when: some_string_value | bool
|
||||
|
||||
To match strings against a regex, use the "match" or "search" filter::
|
||||
|
||||
vars:
|
||||
foo: abcdefg
|
||||
|
||||
tasks:
|
||||
- shell: echo "String '{{ foo }}' matches 'abc'"
|
||||
when: foo | match("abc")
|
||||
|
||||
- shell: echo "String '{{ foo }}' contains 'def'"
|
||||
when: foo | search("def")
|
||||
|
||||
To replace text in a string with regex, use the "regex_replace" filter::
|
||||
|
||||
# convert "ansible" to "able"
|
||||
|
||||
Reference in New Issue
Block a user