mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #6984 from clconway/variable-re-doc
Adds search/match examples to "Playbooks > Variables > Jinja2 Filters" d...
This commit is contained in:
commit
cf54098dab
1 changed files with 12 additions and 0 deletions
|
@ -298,6 +298,18 @@ doesn't know it is a boolean value::
|
||||||
- debug: msg=test
|
- debug: msg=test
|
||||||
when: some_string_value | bool
|
when: some_string_value | bool
|
||||||
|
|
||||||
|
To match strings against a regex, use the "match" or "search" filter::
|
||||||
|
|
||||||
|
vars:
|
||||||
|
url: "http://example.com/users/foo/resources/bar"
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- debug: 'msg="Resource URI: {{ url }}"'
|
||||||
|
when: url | match("http://example.com/users/.*/resources/.*")
|
||||||
|
|
||||||
|
- debug: 'msg="Resource path: {{ url }}"'
|
||||||
|
when: url | search("/users/.*/resources/.*")
|
||||||
|
|
||||||
To replace text in a string with regex, use the "regex_replace" filter::
|
To replace text in a string with regex, use the "regex_replace" filter::
|
||||||
|
|
||||||
# convert "ansible" to "able"
|
# convert "ansible" to "able"
|
||||||
|
|
Loading…
Reference in a new issue