check types for template parameters (#37257)

this should give a better error than when failing on random methods when parameters where the wrong type.
pull/38361/merge
Brian Coca 7 years ago committed by GitHub
parent 8a0c192c36
commit 6ef389617a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -22,9 +22,11 @@ import shutil
import tempfile
from ansible import constants as C
from ansible.config.manager import ensure_type
from ansible.errors import AnsibleError, AnsibleFileNotFound, AnsibleAction, AnsibleActionFail
from ansible.module_utils._text import to_bytes, to_text
from ansible.module_utils.parsing.convert_bool import boolean
from ansible.module_utils.six import string_types
from ansible.plugins.action import ActionBase
from ansible.template import generate_ansible_template_vars
@ -76,6 +78,21 @@ class ActionModule(ActionBase):
newline_sequence = allowed_sequences[wrong_sequences.index(newline_sequence)]
try:
for s_type in ('source', 'dest', 'state', 'newline_sequence', 'variable_start_string', 'variable_end_string', 'block_start_string',
'block_end_string'):
value = locals()[s_type]
value = ensure_type(value, 'string')
if value is not None and not isinstance(value, string_types):
raise AnsibleActionFail("%s is expected to be a string, but got %s instead" % (s_type, type(value)))
locals()[s_type] = value
for b_type in ('force', 'follow', 'trim_blocks'):
value = locals()[b_type]
value = ensure_type(value, 'string')
if value is not None and not isinstance(value, bool):
raise AnsibleActionFail("%s is expected to be a boolean, but got %s instead" % (b_type, type(value)))
locals()[b_type] = value
if state is not None:
raise AnsibleActionFail("'state' cannot be specified on a template")
elif source is None or dest is None:

Loading…
Cancel
Save