From beba4c5a1acab36370104baf535164a1e78ca159 Mon Sep 17 00:00:00 2001 From: Chris Conway Date: Mon, 14 Apr 2014 08:25:41 -0700 Subject: [PATCH] Adds search/match examples to "Playbooks > Variables > Jinja2 Filters" doc section. --- docsite/rst/playbooks_variables.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docsite/rst/playbooks_variables.rst b/docsite/rst/playbooks_variables.rst index ce70daf54ff..8ae0b92c305 100644 --- a/docsite/rst/playbooks_variables.rst +++ b/docsite/rst/playbooks_variables.rst @@ -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"