diff options
author | Adam Miller <admiller@redhat.com> | 2018-05-17 15:29:36 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-17 15:29:36 -0500 |
commit | 98a198a777897297ea1890e36df1a485572608ee (patch) | |
tree | 44f94e34fc0f2356d7c96624b28b0adef1ecb54e | |
parent | 6a4f3fb729a00861982a0a7ca041f4160aca2aff (diff) | |
download | ansible-98a198a777897297ea1890e36df1a485572608ee.tar.gz |
Handle incorrect data type in list lookup plugin (#35483)
handle incorrect data type in list lookup plugin
Fixes #35481
test to ensure that loops properly handle incorrect datatypes
Signed-off-by: Adam Miller <admiller@redhat.com>
-rw-r--r-- | lib/ansible/plugins/lookup/list.py | 6 | ||||
-rw-r--r-- | test/integration/targets/loops/tasks/main.yml | 21 |
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/ansible/plugins/lookup/list.py b/lib/ansible/plugins/lookup/list.py index 96a819719f..a2fca7ce79 100644 --- a/lib/ansible/plugins/lookup/list.py +++ b/lib/ansible/plugins/lookup/list.py @@ -3,6 +3,7 @@ # Make coding more python3-ish from __future__ import (absolute_import, division, print_function) + __metaclass__ = type DOCUMENTATION = """ @@ -27,10 +28,15 @@ RETURN = """ _list: description: basically the same as you fed in """ +import collections + from ansible.plugins.lookup import LookupBase +from ansible.errors import AnsibleError class LookupModule(LookupBase): def run(self, terms, **kwargs): + if not isinstance(terms, collections.Sequence): + raise AnsibleError("with_list expects a list") return terms diff --git a/test/integration/targets/loops/tasks/main.yml b/test/integration/targets/loops/tasks/main.yml index af7e53a502..2c83d2f0fa 100644 --- a/test/integration/targets/loops/tasks/main.yml +++ b/test/integration/targets/loops/tasks/main.yml @@ -202,3 +202,24 @@ that: - "output.results[0]['_ansible_item_label'] == 'looped_var foo_label'" - "output.results[1]['_ansible_item_label'] == 'looped_var bar_label'" + +# The following test cases are to ensure that we don't have a regression on +# GitHub Issue https://github.com/ansible/ansible/issues/35481 +# +# This should execute and not cause a RuntimeError +- debug: + msg: "with_dict passed a list: {{item}}" + with_dict: "{{ a_list }}" + register: with_dict_passed_a_list + ignore_errors: True +- assert: + that: + - with_dict_passed_a_list is failed +- debug: + msg: "with_list passed a dict: {{item}}" + with_list: "{{ a_dict }}" + register: with_list_passed_a_dict + ignore_errors: True +- assert: + that: + - with_list_passed_a_dict is failed |