From a37f55d32e10cf33ba5a858ff045f6fb8b4aa982 Mon Sep 17 00:00:00 2001 From: Jeroen Hoekx Date: Sat, 29 Jun 2013 16:01:34 +0200 Subject: [PATCH] Add a mandatory jinja2 filter for use in templates. --- lib/ansible/runner/filter_plugins/core.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/ansible/runner/filter_plugins/core.py b/lib/ansible/runner/filter_plugins/core.py index 8895da656d..1b1792e770 100644 --- a/lib/ansible/runner/filter_plugins/core.py +++ b/lib/ansible/runner/filter_plugins/core.py @@ -43,6 +43,12 @@ def failed(*a, **kw): def success(*a, **kw): return not failed(*a, **kw) +def mandatory(a): + ''' Make a variable mandatory ''' + if not a: + raise errors.AnsibleError('Mandatory variable not defined.') + return a + class FilterModule(object): ''' Ansible core jinja2 filters ''' @@ -70,5 +76,7 @@ class FilterModule(object): 'failed' : failed, 'success' : success, + # variable existence + 'mandatory': mandatory, }