mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 22:33:25 +00:00
added defined/undefined tests
This commit is contained in:
@@ -84,6 +84,15 @@ def search(value, pattern='', ignorecase=False, multiline=False):
|
|||||||
''' Perform a `re.search` returning a boolean '''
|
''' Perform a `re.search` returning a boolean '''
|
||||||
return regex(value, pattern, ignorecase, multiline, 'search')
|
return regex(value, pattern, ignorecase, multiline, 'search')
|
||||||
|
|
||||||
|
def undefined(a):
|
||||||
|
''' Test if a variable is undefined '''
|
||||||
|
from jinja2.runtime import Undefined
|
||||||
|
return isinstance(a, Undefined)
|
||||||
|
|
||||||
|
def defined(a):
|
||||||
|
''' Test if a variable is defined '''
|
||||||
|
return not undefined(a)
|
||||||
|
|
||||||
class TestModule(object):
|
class TestModule(object):
|
||||||
''' Ansible core jinja2 tests '''
|
''' Ansible core jinja2 tests '''
|
||||||
|
|
||||||
@@ -107,4 +116,8 @@ class TestModule(object):
|
|||||||
'match': match,
|
'match': match,
|
||||||
'search': search,
|
'search': search,
|
||||||
'regex': regex,
|
'regex': regex,
|
||||||
|
|
||||||
|
# variable testing
|
||||||
|
'undefined': undefined,
|
||||||
|
'defined': defined,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user