From 0eead1a3f67f0b0f10387a25f01e3142b1f71934 Mon Sep 17 00:00:00 2001 From: Fran Torres-Lopez Date: Fri, 22 Apr 2016 15:23:17 -0500 Subject: [PATCH] Add example of checking registered variable for emptiness. (#15510) --- docsite/rst/playbooks_conditionals.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docsite/rst/playbooks_conditionals.rst b/docsite/rst/playbooks_conditionals.rst index f28ee4ec0b1..f66f2a89c7d 100644 --- a/docsite/rst/playbooks_conditionals.rst +++ b/docsite/rst/playbooks_conditionals.rst @@ -271,6 +271,22 @@ fields:: with_items: home_dirs.stdout_lines # same as with_items: home_dirs.stdout.split() +As shown previously, the registered variable's string contents are accessible with the 'stdout' value. +You may check the registered variable's string contents for emptiness:: + + - name: check registered variable for emptiness + hosts: all + + tasks: + + - name: list contents of directory + command: ls mydir + register: contents + + - name: check contents for emptiness + debug: msg="Directory is empty" + when: contents.stdout == "" + .. seealso::