From f150fe2c232a9eb3a3863ed30690397c922de6e1 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 21 Aug 2015 09:54:56 -0400 Subject: [PATCH] moved mandatory back to filters as it does not always return a boolean, it does an exception on failure --- lib/ansible/plugins/filter/core.py | 10 ++++++++++ lib/ansible/plugins/test/core.py | 11 ----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py index c0edbe0366..84e055b61f 100644 --- a/lib/ansible/plugins/filter/core.py +++ b/lib/ansible/plugins/filter/core.py @@ -223,6 +223,14 @@ def get_encrypted_password(password, hashtype='sha512', salt=None): def to_uuid(string): return str(uuid.uuid5(UUID_NAMESPACE_ANSIBLE, str(string))) +def mandatory(a): + from jinja2.runtime import Undefined + + ''' Make a variable mandatory ''' + if isinstance(a, Undefined): + raise errors.AnsibleFilterError('Mandatory variable not defined.') + return a + class FilterModule(object): ''' Ansible core jinja2 filters ''' @@ -290,4 +298,6 @@ class FilterModule(object): # random stuff 'random': rand, 'shuffle': randomize_list, + # undefined + 'mandatory': mandatory, } diff --git a/lib/ansible/plugins/test/core.py b/lib/ansible/plugins/test/core.py index 7de8e7436c..daf2240211 100644 --- a/lib/ansible/plugins/test/core.py +++ b/lib/ansible/plugins/test/core.py @@ -79,14 +79,6 @@ def search(value, pattern='', ignorecase=False): ''' Perform a `re.search` returning a boolean ''' return regex(value, pattern, ignorecase, 'search') -def mandatory(a): - from jinja2.runtime import Undefined - - ''' Make a variable mandatory ''' - if isinstance(a, Undefined): - raise errors.AnsibleFilterError('Mandatory variable not defined.') - return a - class TestModule(object): ''' Ansible core jinja2 tests ''' @@ -102,9 +94,6 @@ class TestModule(object): # skip testing 'skipped' : skipped, - # variable existence - 'mandatory': mandatory, - # regex 'match': match, 'search': search,