From 02f4d0a57fac71eb9fdb909fd228ec4d4adcf61e Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Tue, 16 Oct 2018 13:35:10 -0500 Subject: [PATCH] Ensure that an empty literal list with loop skips the task (#47129) --- changelogs/fragments/loop-empty-literal-list.yaml | 2 ++ lib/ansible/executor/task_executor.py | 2 +- test/integration/targets/loops/tasks/main.yml | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/loop-empty-literal-list.yaml diff --git a/changelogs/fragments/loop-empty-literal-list.yaml b/changelogs/fragments/loop-empty-literal-list.yaml new file mode 100644 index 0000000000..f86f5b5d11 --- /dev/null +++ b/changelogs/fragments/loop-empty-literal-list.yaml @@ -0,0 +1,2 @@ +bugfixes: +- loop - Do not evaluate a empty literal list ``[]`` as falsy, it should instead cause the task to skip () diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index d1f67af8a2..2666666d40 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -236,7 +236,7 @@ class TaskExecutor: else: raise AnsibleError("Unexpected failure in finding the lookup named '%s' in the available lookup plugins" % self._task.loop_with) - elif self._task.loop: + elif self._task.loop is not None: items = templar.template(self._task.loop) if not isinstance(items, list): raise AnsibleError( diff --git a/test/integration/targets/loops/tasks/main.yml b/test/integration/targets/loops/tasks/main.yml index 1b8a745050..8cdd612aaa 100644 --- a/test/integration/targets/loops/tasks/main.yml +++ b/test/integration/targets/loops/tasks/main.yml @@ -252,3 +252,9 @@ loop: "{{ fake_var }}" register: result failed_when: result is not skipped + +- name: Loop on literal empty list + debug: + loop: [] + register: literal_empty_list + failed_when: literal_empty_list is not skipped