Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Jinja2 filter |bool : return boolean interpretation of the value #3418

Merged
merged 1 commit into from
Jul 3, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/ansible/runner/filter_plugins/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import json
import os.path
import yaml
import types
from ansible import errors

def to_nice_yaml(*a, **kw):
Expand Down Expand Up @@ -49,6 +50,17 @@ def mandatory(a):
raise errors.AnsibleError('Mandatory variable not defined.')
return a

def bool(a):
''' return a bool for the arg '''
if a is None or type(a) == bool:
return a
if type(a) in types.StringTypes:
a = a.lower()
if a in ['yes', 'on', '1', 'true', 1]:
return True
else:
return False

class FilterModule(object):
''' Ansible core jinja2 filters '''

Expand Down Expand Up @@ -78,5 +90,8 @@ def filters(self):

# variable existence
'mandatory': mandatory,

# value as boolean
'bool': bool,
}