Discussion:
[ansible-project] How to check if previous shell task returns an empty string
Dump Hole
2015-07-23 19:18:12 UTC
Permalink
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.
--
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-project+***@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
2015-07-23 19:42:02 UTC
Permalink
i think you want:
result.stdout|length > 0
Post by Dump Hole
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.
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.
--
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
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
--
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-project+***@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/CAJ5XC8nzL7hiK_K7Jf0WcE3SLcNWBd2dS%3Dy-v8AOY3-VuikbSg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...