How to check if previous shell task returns an empty string

2,036 views
Skip to first unread message

Dump Hole

unread,
Jul 23, 2015, 3:40:21 PM7/23/15
to Ansible Project
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.

Brian Coca

unread,
Jul 23, 2015, 3:42:06 PM7/23/15
to Ansible Project
i think you want:
result.stdout|length > 0
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/c23f50bf-a7f4-4217-a126-ab17d78178d7%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca
Reply all
Reply to author
Forward
0 new messages