do not accept array as extra_vars

related to #5645

* Since we pass extra_vars to ansible as -e; we require that the top
most data-structure be a key-value. NOT an array.
This commit is contained in:
Chris Meyers
2017-07-19 11:30:00 -04:00
parent f31cec2848
commit 802f722e95
3 changed files with 42 additions and 4 deletions

View File

@@ -179,15 +179,21 @@ def vars_validate_or_raise(vars_str):
job templates, inventories, or hosts are either an acceptable
blank string, or are valid JSON or YAML dict
"""
try:
json.loads((vars_str or '').strip() or '{}')
if isinstance(vars_str, dict) or (isinstance(vars_str, basestring) and vars_str == '""'):
return vars_str
try:
r = json.loads((vars_str or '').strip() or '{}')
if isinstance(r, dict):
return vars_str
except ValueError:
pass
try:
r = yaml.safe_load(vars_str)
if not (isinstance(r, basestring) and r.startswith('OrderedDict(')):
# Can be None if '---'
if isinstance(r, dict) or r is None:
return vars_str
except yaml.YAMLError:
pass
raise RestValidationError(_('Must be valid JSON or YAML.'))