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
b07ce8b9
Commit
b07ce8b9
authored
Dec 16, 2014
by
Brian Coca
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed redundant math functions as jinja2 provides abs() and round()
already
parent
6a3c26eb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
37 deletions
+2
-37
docsite/rst/playbooks_variables.rst
+2
-8
lib/ansible/runner/filter_plugins/math.py
+0
-29
No files found.
docsite/rst/playbooks_variables.rst
View file @
b07ce8b9
...
...
@@ -318,19 +318,11 @@ Math
--------------------
.. versionadded:: 1.9
To get the absolute value of a number::
{{ -23 | abs }}
To see if something is actually a number::
{{ myvar | isnan }}
Rounding::
{{ myvar | ceil }}
{{ myvar | floor }}
Get the logarithm (default is e)::
{{ myvar | log }}
...
...
@@ -349,6 +341,8 @@ Square root, or the 5th::
{{ myvar | root }}
{{ myvar | root(5) }}
Note that jinja2 already provides some like abs() and round().
.. _other_useful_filters:
...
...
lib/ansible/runner/filter_plugins/math.py
View file @
b07ce8b9
...
...
@@ -18,30 +18,6 @@
import
math
from
ansible
import
errors
def
absolute
(
x
):
if
isinstance
(
x
,
float
):
return
math
.
fabs
(
x
)
elif
isinstance
(
x
,
int
):
return
abs
(
x
)
else
raise
errors
.
AnsibleFilterError
(
'abs() can only be used on numbers'
)
def
cieling
(
x
):
try
:
return
math
.
ciel
(
x
)
except
TypeError
,
e
:
raise
errors
.
AnsibleFilterError
(
'ciel() can only be used on floats:
%
s'
%
str
(
e
))
def
flooring
(
x
):
try
:
return
math
.
floor
(
x
)
except
TypeError
,
e
:
raise
errors
.
AnsibleFilterError
(
'floor() can only be used on floats:
%
s'
%
str
(
e
))
def
isnotanumber
(
x
):
try
:
return
math
.
isnan
(
x
)
...
...
@@ -82,13 +58,8 @@ class FilterModule(object):
def
filters
(
self
):
return
{
# general math
'abs'
:
absolute
,
'isnan'
:
isnotanumber
,
# rounding
'ceil'
:
cieling
,
'floor'
:
flooring
,
# exponents and logarithms
'log'
:
logarithm
,
'pow'
:
power
,
...
...
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