moved mandatory back to filters as it does not always return a boolean, it does an exception on failure
This commit is contained in:
parent
01708cc824
commit
f150fe2c23
2 changed files with 10 additions and 11 deletions
|
@ -223,6 +223,14 @@ def get_encrypted_password(password, hashtype='sha512', salt=None):
|
||||||
def to_uuid(string):
|
def to_uuid(string):
|
||||||
return str(uuid.uuid5(UUID_NAMESPACE_ANSIBLE, str(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):
|
class FilterModule(object):
|
||||||
''' Ansible core jinja2 filters '''
|
''' Ansible core jinja2 filters '''
|
||||||
|
|
||||||
|
@ -290,4 +298,6 @@ class FilterModule(object):
|
||||||
# random stuff
|
# random stuff
|
||||||
'random': rand,
|
'random': rand,
|
||||||
'shuffle': randomize_list,
|
'shuffle': randomize_list,
|
||||||
|
# undefined
|
||||||
|
'mandatory': mandatory,
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,14 +79,6 @@ def search(value, pattern='', ignorecase=False):
|
||||||
''' Perform a `re.search` returning a boolean '''
|
''' Perform a `re.search` returning a boolean '''
|
||||||
return regex(value, pattern, ignorecase, 'search')
|
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):
|
class TestModule(object):
|
||||||
''' Ansible core jinja2 tests '''
|
''' Ansible core jinja2 tests '''
|
||||||
|
|
||||||
|
@ -102,9 +94,6 @@ class TestModule(object):
|
||||||
# skip testing
|
# skip testing
|
||||||
'skipped' : skipped,
|
'skipped' : skipped,
|
||||||
|
|
||||||
# variable existence
|
|
||||||
'mandatory': mandatory,
|
|
||||||
|
|
||||||
# regex
|
# regex
|
||||||
'match': match,
|
'match': match,
|
||||||
'search': search,
|
'search': search,
|
||||||
|
|
Loading…
Reference in a new issue