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
efba8b47
Commit
efba8b47
authored
Mar 31, 2014
by
James Tanner
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'regexreplace' of
git://github.com/jacobweber/ansible
into jacobweber-regexreplace
parents
7f7e2a69
35742fe0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
0 deletions
+25
-0
lib/ansible/runner/filter_plugins/core.py
+10
-0
test/units/TestFilters.py
+15
-0
No files found.
lib/ansible/runner/filter_plugins/core.py
View file @
efba8b47
...
...
@@ -127,6 +127,15 @@ def search(value, pattern='', ignorecase=False):
''' Perform a `re.search` returning a boolean '''
return
regex
(
value
,
pattern
,
ignorecase
,
'search'
)
def
regex_replace
(
value
=
''
,
pattern
=
''
,
replacement
=
''
,
ignorecase
=
False
):
''' Perform a `re.sub` returning a string '''
if
ignorecase
:
flags
=
re
.
I
else
:
flags
=
0
_re
=
re
.
compile
(
pattern
,
flags
=
flags
)
return
_re
.
sub
(
replacement
,
value
)
def
unique
(
a
):
return
set
(
a
)
...
...
@@ -196,6 +205,7 @@ class FilterModule(object):
'match'
:
match
,
'search'
:
search
,
'regex'
:
regex
,
'regex_replace'
:
regex_replace
,
# list
'unique'
:
unique
,
...
...
test/units/TestFilters.py
View file @
efba8b47
...
...
@@ -116,6 +116,21 @@ class TestFilters(unittest.TestCase):
True
)
assert
a
==
True
def
test_regex_replace_case_sensitive
(
self
):
a
=
ansible
.
runner
.
filter_plugins
.
core
.
regex_replace
(
'ansible'
,
'^a.*i(.*)$'
,
'a
\\
1'
)
assert
a
==
'able'
def
test_regex_replace_case_insensitive
(
self
):
a
=
ansible
.
runner
.
filter_plugins
.
core
.
regex_replace
(
'ansible'
,
'^A.*I(.*)$'
,
'a
\\
1'
,
True
)
assert
a
==
'able'
def
test_regex_replace_no_match
(
self
):
a
=
ansible
.
runner
.
filter_plugins
.
core
.
regex_replace
(
'ansible'
,
'^b.*i(.*)$'
,
'a
\\
1'
)
assert
a
==
'ansible'
#def test_filters(self):
# this test is pretty low level using a playbook, hence I am disabling it for now -- MPD.
...
...
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