Conditionals — Ansible Documentation
docs.ansible.com › ansible › latestDec 21, 2021 · If you want to run another task only on hosts where the stdout of your registered variable is empty, check the registered variable’s string contents for emptiness: - name : check registered variable for emptiness hosts : all tasks : - name : List contents of directory ansible.builtin.command : ls mydir register : contents - name : Check contents for emptiness ansible.builtin.debug : msg : "Directory is empty" when : contents.stdout == ""