Checking output of a shell command in ansible


I’m trying to write an Ansible script that runs a shell pipeline, and determines whether to terminate the playbook’s execution based on that pipeline’s output.

Here is the problematic code:

Here is the error:

Can someone tells me what could be the issue?


Consider doing the comparison in your shell command:

You don’t need to use register at all here, since the default failedWhen is when the exit status of a command is nonzero.

If you did want to use register, however:

Note the use of failed_when instead of when: A when clause determines if a command is going to be run at all, whereas a failed_when clause determines whether that command is determined to have failed.

Leave a Reply