From c20285782d1e483bc9bea071cf78f1c8a3e89048 Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Tue, 6 Jun 2017 02:48:18 -0400 Subject: [PATCH] test conditionals work for invalid elements in list and undefined keys in dicts (#23875) --- .../targets/conditionals/tasks/main.yml | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/test/integration/targets/conditionals/tasks/main.yml b/test/integration/targets/conditionals/tasks/main.yml index 23f4afe54e2..868cffe2afa 100644 --- a/test/integration/targets/conditionals/tasks/main.yml +++ b/test/integration/targets/conditionals/tasks/main.yml @@ -307,3 +307,55 @@ - name: test complex templated condition debug: msg="it works" when: vars_file_var in things1|union([vars_file_var]) + +- name: test dict with invalid key is undefined + vars: + mydict: + a: foo + b: bar + debug: var=mydict['c'] + register: result + when: mydict['c'] is undefined + +- name: assert the task did not fail + assert: + that: + - "result.failed == false" + +- name: test dict with invalid key does not run with conditional is defined + vars: + mydict: + a: foo + b: bar + debug: var=mydict['c'] + when: mydict['c'] is defined + register: result + +- name: assert the task was skipped + assert: + that: + - "result.skipped == true" + +- name: test list with invalid element does not run with conditional is defined + vars: + mylist: [] + debug: var=mylist[0] + when: mylist[0] is defined + register: result + +- name: assert the task was skipped + assert: + that: + - "result.skipped == true" + +- name: test list with invalid element is undefined + vars: + mylist: [] + debug: var=mylist[0] + when: mylist[0] is undefined + register: result + +- name: assert the task did not fail + assert: + that: + - "result.failed == false"