fix combine filter using undefined vars (#55840)

* Check variables are defined before using combine filter

* Add tests for the combine filter

* Remove dependencies that should already be installed

* relocate the function to recursively check for undefined vars

add another test

* changelog
This commit is contained in:
Sloane Hertel
2019-04-30 11:10:20 -04:00
committed by Brian Coca
parent c4004b5fb1
commit 11279a909d
4 changed files with 53 additions and 0 deletions

View File

@@ -178,6 +178,20 @@ def _count_newlines_from_end(in_str):
return i
def recursive_check_defined(item):
from jinja2.runtime import Undefined
if isinstance(item, MutableMapping):
for key in item:
recursive_check_defined(item[key])
elif isinstance(item, list):
for i in item:
recursive_check_defined(i)
else:
if isinstance(item, Undefined):
raise AnsibleFilterError("{0} is undefined".format(item))
class AnsibleUndefined(StrictUndefined):
'''
A custom Undefined class, which returns further Undefined objects on access,