Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
a78ed39f
Commit
a78ed39f
authored
Jul 26, 2015
by
James Cammarata
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11743 from renard/regex_escape-filter
Regex escape filter
parents
db4b3544
c0b7fcd3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
0 deletions
+10
-0
docsite/rst/playbooks_filters.rst
+5
-0
lib/ansible/plugins/filter/core.py
+5
-0
No files found.
docsite/rst/playbooks_filters.rst
View file @
a78ed39f
...
@@ -401,6 +401,11 @@ To replace text in a string with regex, use the "regex_replace" filter::
...
@@ -401,6 +401,11 @@ To replace text in a string with regex, use the "regex_replace" filter::
.. note:: If "regex_replace" filter is used with variables inside YAML arguments (as opposed to simpler 'key=value' arguments),
.. note:: If "regex_replace" filter is used with variables inside YAML arguments (as opposed to simpler 'key=value' arguments),
then you need to escape backreferences (e.g. ``\\1``) with 4 backslashes (``\\\\``) instead of 2 (``\\``).
then you need to escape backreferences (e.g. ``\\1``) with 4 backslashes (``\\\\``) instead of 2 (``\\``).
To escape special characters within a regex, use the "regex_escape" filter::
# convert '^f.*o(.*)$' to '\^f\.\*o\(\.\*\)\$'
{{ '^f.*o(.*)$' | regex_escape() }}
A few useful filters are typically added with each new Ansible release. The development documentation shows
A few useful filters are typically added with each new Ansible release. The development documentation shows
how to extend Ansible filters by writing your own as plugins, though in general, we encourage new ones
how to extend Ansible filters by writing your own as plugins, though in general, we encourage new ones
to be added to core so everyone can make use of them.
to be added to core so everyone can make use of them.
...
...
lib/ansible/plugins/filter/core.py
View file @
a78ed39f
...
@@ -222,6 +222,10 @@ def version_compare(value, version, operator='eq', strict=False):
...
@@ -222,6 +222,10 @@ def version_compare(value, version, operator='eq', strict=False):
except
Exception
,
e
:
except
Exception
,
e
:
raise
errors
.
AnsibleFilterError
(
'Version comparison:
%
s'
%
e
)
raise
errors
.
AnsibleFilterError
(
'Version comparison:
%
s'
%
e
)
def
regex_escape
(
string
):
'''Escape all regular expressions special characters from STRING.'''
return
re
.
escape
(
string
)
@environmentfilter
@environmentfilter
def
rand
(
environment
,
end
,
start
=
None
,
step
=
None
):
def
rand
(
environment
,
end
,
start
=
None
,
step
=
None
):
r
=
SystemRandom
()
r
=
SystemRandom
()
...
@@ -356,6 +360,7 @@ class FilterModule(object):
...
@@ -356,6 +360,7 @@ class FilterModule(object):
'search'
:
search
,
'search'
:
search
,
'regex'
:
regex
,
'regex'
:
regex
,
'regex_replace'
:
regex_replace
,
'regex_replace'
:
regex_replace
,
'regex_escape'
:
regex_escape
,
# ? : ;
# ? : ;
'ternary'
:
ternary
,
'ternary'
:
ternary
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment