Throw an error on unsupported vars_prompt keys (#65487)
This commit is contained in:
parent
b975fd407d
commit
8a409f37db
4 changed files with 31 additions and 3 deletions
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- vars_prompt - throw error when encountering unsupported key
|
|
@ -211,9 +211,11 @@ class Play(Base, Taggable, CollectionSearch):
|
|||
if new_ds is not None:
|
||||
for prompt_data in new_ds:
|
||||
if 'name' not in prompt_data:
|
||||
raise AnsibleParserError("Invalid vars_prompt data structure", obj=ds)
|
||||
else:
|
||||
vars_prompts.append(prompt_data)
|
||||
raise AnsibleParserError("Invalid vars_prompt data structure, missing 'name' key", obj=ds)
|
||||
for key in prompt_data:
|
||||
if key not in ('name', 'prompt', 'default', 'private', 'confirm', 'encrypt', 'salt_size', 'salt', 'unsafe'):
|
||||
raise AnsibleParserError("Invalid vars_prompt data structure, found unsupported key '%s'" % key, obj=ds)
|
||||
vars_prompts.append(prompt_data)
|
||||
return vars_prompts
|
||||
|
||||
def _compile_roles(self):
|
||||
|
|
|
@ -115,6 +115,12 @@ tests = [
|
|||
'test_spec': [
|
||||
[('prompting for variable:', '{{whole}}\r')],
|
||||
r'testhost.*ok=2']},
|
||||
|
||||
# Test unsupported keys
|
||||
{'playbook': 'unsupported.yml',
|
||||
'test_spec': [
|
||||
[],
|
||||
"Invalid vars_prompt data structure, found unsupported key 'when'"]},
|
||||
]
|
||||
|
||||
for t in tests:
|
||||
|
|
18
test/integration/targets/vars_prompt/unsupported.yml
Normal file
18
test/integration/targets/vars_prompt/unsupported.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
- name: Test vars_prompt unsupported key
|
||||
hosts: testhost
|
||||
become: no
|
||||
gather_facts: no
|
||||
vars_prompt:
|
||||
- name: input
|
||||
prompt: prompting for variable
|
||||
# Unsupported key for vars_prompt
|
||||
when: foo is defined
|
||||
|
||||
tasks:
|
||||
- name:
|
||||
assert:
|
||||
that:
|
||||
- input is not defined
|
||||
|
||||
- debug:
|
||||
var: input
|
Loading…
Reference in a new issue