From 106e942faa9f20fd55c00ca05dd564f0be05490f Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Sat, 25 Jul 2015 14:05:27 +0200 Subject: [PATCH] Document and test 'is undefined' rather than 'is not defined' According to https://github.com/ansible/ansible/issues/10273, this syntax should work better for nested dicts. --- docsite/rst/playbooks_conditionals.rst | 2 +- .../integration/roles/test_conditionals/tasks/main.yml | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docsite/rst/playbooks_conditionals.rst b/docsite/rst/playbooks_conditionals.rst index bdadaf59715..f441ed659eb 100644 --- a/docsite/rst/playbooks_conditionals.rst +++ b/docsite/rst/playbooks_conditionals.rst @@ -90,7 +90,7 @@ If a required variable has not been set, you can skip or fail using Jinja2's when: foo is defined - fail: msg="Bailing out. this play requires 'bar'" - when: bar is not defined + when: bar is undefined This is especially useful in combination with the conditional import of vars files (see below). diff --git a/test/integration/roles/test_conditionals/tasks/main.yml b/test/integration/roles/test_conditionals/tasks/main.yml index 4a2420408ac..c4731a206b9 100644 --- a/test/integration/roles/test_conditionals/tasks/main.yml +++ b/test/integration/roles/test_conditionals/tasks/main.yml @@ -148,6 +148,16 @@ that: - "result.skipped == true" +- name: test bad conditional 'is undefined' + shell: echo 'testing' + when: test_bare is undefined + register: result + +- name: assert bad conditional 'is undefined' did NOT run + assert: + that: + - "result.skipped == true" + - name: test bare conditional shell: echo 'testing' when: test_bare