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
3ba516ac
Commit
3ba516ac
authored
Jun 19, 2014
by
Michael Peters
Committed by
Michael DeHaan
Aug 08, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding min() and max() filters for use in Jinja templates
parent
2d2178f2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
0 deletions
+32
-0
docsite/rst/playbooks_variables.rst
+14
-0
lib/ansible/runner/filter_plugins/core.py
+10
-0
test/units/TestFilters.py
+8
-0
No files found.
docsite/rst/playbooks_variables.rst
View file @
3ba516ac
...
...
@@ -180,6 +180,20 @@ Jinja2 provides a useful 'default' filter, that is often a better approach to fa
In the above example, if the variable 'some_variable' is not defined, the value used will be 5, rather than an error
being raised.
.. _list_filters:
List Filters
--------------------
.. versionadded:: 1.7
To get the minimum value from list of numbers::
{{ list1 | min }}
To get the maximum value from a list of numbers::
{{ [3, 4, 2] | max }}
.. _set_theory_filters:
Set Theory Filters
...
...
lib/ansible/runner/filter_plugins/core.py
View file @
3ba516ac
...
...
@@ -183,6 +183,14 @@ def union(a, b):
c
=
unique
(
a
+
b
)
return
c
def
min
(
a
):
_min
=
__builtins__
.
get
(
'min'
)
return
_min
(
a
);
def
max
(
a
):
_max
=
__builtins__
.
get
(
'max'
)
return
_max
(
a
);
def
version_compare
(
value
,
version
,
operator
=
'eq'
,
strict
=
False
):
''' Perform a version comparison on a value '''
op_map
=
{
...
...
@@ -289,6 +297,8 @@ class FilterModule(object):
'difference'
:
difference
,
'symmetric_difference'
:
symmetric_difference
,
'union'
:
union
,
'min'
:
min
,
'max'
:
max
,
# version comparison
'version_compare'
:
version_compare
,
...
...
test/units/TestFilters.py
View file @
3ba516ac
...
...
@@ -175,3 +175,11 @@ class TestFilters(unittest.TestCase):
self
.
assertTrue
(
ansible
.
runner
.
filter_plugins
.
core
.
version_compare
(
1.0
,
1.1
,
'<='
))
self
.
assertTrue
(
ansible
.
runner
.
filter_plugins
.
core
.
version_compare
(
'12.04'
,
12
,
'ge'
))
def
test_min
(
self
):
a
=
ansible
.
runner
.
filter_plugins
.
core
.
min
([
3
,
2
,
5
,
4
])
assert
a
==
2
def
test_max
(
self
):
a
=
ansible
.
runner
.
filter_plugins
.
core
.
max
([
3
,
2
,
5
,
4
])
assert
a
==
5
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