only_if conditions key off exit value?


#1

I’m having some issues with an only_if condition that works on Linux
but seems to be having issues on Solaris, and I want to make sure I
understand how Chef is handling it.

I have an only_if as follows:

only_if “mysql -u root -h localhost -e ‘SHOW STATUS;’”

If the MySQL root user still has no password, the command will succeed
and the exit status will be 0. However, if the root user now has a
password, the command will fail and the exit status will be 1. My
understanding is the the only_if will be True if the exit status from
the command is 0. Is this incorrect?

-J


#2

On Friday, September 16, 2011 at 1:35 AM, Jason J. W. Williams wrote:

I’m having some issues with an only_if condition that works on Linux
but seems to be having issues on Solaris, and I want to make sure I
understand how Chef is handling it.

I have an only_if as follows:

only_if “mysql -u root -h localhost -e ‘SHOW STATUS;’”

If the MySQL root user still has no password, the command will succeed
and the exit status will be 0. However, if the root user now has a
password, the command will fail and the exit status will be 1. My
understanding is the the only_if will be True if the exit status from
the command is 0. Is this incorrect?

-J
You’ve got it right, 0 is true, anything else is false. Running with -l debug might provide more insight into what’s going on.


Dan DeLeo


#3

On Fri, Sep 16, 2011 at 9:42 AM, Daniel DeLeo dan@kallistec.com wrote:

On Friday, September 16, 2011 at 1:35 AM, Jason J. W. Williams wrote:

I’m having some issues with an only_if condition that works on Linux
but seems to be having issues on Solaris, and I want to make sure I
understand how Chef is handling it.

I have an only_if as follows:

only_if “mysql -u root -h localhost -e ‘SHOW STATUS;’”

If the MySQL root user still has no password, the command will succeed
and the exit status will be 0. However, if the root user now has a
password, the command will fail and the exit status will be 1. My
understanding is the the only_if will be True if the exit status from
the command is 0. Is this incorrect?

You’ve got it right, 0 is true, anything else is false. Running with -l debug might provide more insight into what’s going on.

What appears to have been causing it to execute anyway is that I had
two only_if conditions. The one I listed was not being triggered but
the second once checking for the MySQL local socket file was true. So
it appears if you have multiple only_if conditions only one has to be
true for the block to execute. By converting the second only_if to a
not_if, the block is working properly now.

-J