From b07ce8b942d1d659257b0aebb6a17e1425e583d1 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 16 Dec 2014 17:57:21 -0500 Subject: [PATCH] removed redundant math functions as jinja2 provides abs() and round() already --- docsite/rst/playbooks_variables.rst | 10 ++------ lib/ansible/runner/filter_plugins/math.py | 29 ----------------------- 2 files changed, 2 insertions(+), 37 deletions(-) diff --git a/docsite/rst/playbooks_variables.rst b/docsite/rst/playbooks_variables.rst index a341fa44e73..c272f160a5f 100644 --- a/docsite/rst/playbooks_variables.rst +++ b/docsite/rst/playbooks_variables.rst @@ -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: diff --git a/lib/ansible/runner/filter_plugins/math.py b/lib/ansible/runner/filter_plugins/math.py index f49635af721..ce01ae573b5 100644 --- a/lib/ansible/runner/filter_plugins/math.py +++ b/lib/ansible/runner/filter_plugins/math.py @@ -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,