How to check if previous shell task returns an empty string

I have two shell tasks. The first one runs a check and returns a list of ids to be removed. The second one will remove these ids.

The stdout of the first task looks like this:
1
2
3
4

which then gets fed into the second task to remove 1, 2, 3, 4

But if the first one cannot find ids to be removed, it will instead return an empty string rather than an error. How do I check in Ansible for an empty string, and how do I pass I set the variable through register

  • name: task1
    shell: script1
    register: result
  • name: task2
    shell: script2 script1
    when: result.length() > 0 <<< ??

I tried with stdout_lines.length(), length, size(), size, len(). No luck.

i think you want:
  result.stdout|length > 0