How to Change Skip Message for Controls?

Hi - I was looking at the docs around the use of only_if in and see that we can skip controls based on a condition. There was mention of the skip message (which always seem to default to "Skipped control due to only_if condition") but I don't see where that should be set. Also, the code snippet in the docs for only_if is not working for me but if I make it like so it works:

only_if do



Any help to make the skip message more meaningful is appreciated. TIA!

only_if takes an optional String message parameter and a required block that should evaluate to a Boolean; if the block is false, the control will skip, with the message "Skipped due to YOURMESSAGE". It's mentioned on the InSpec DSL page you linked to (perhaps not prominently):

  only_if('redis is not installed.') do

That's how it's supposed to work :slight_smile:

You said it's "not working for you" - could you give more detail? Ruby syntax around block calls with a parameter can be sensitive to spaces....

# This is OK
 only_if("it is Friday") { false }

# This will probably be a syntax error - note the space after "if"
 only_if ("it is Friday") { false }

What error are you seeing?

Thanks for the reply @cwolfe! Here's the error message I get if I follow the doc (whenever I put a message):

wrong number of arguments (given 1, expected 0)

Oh and we are using InSpec version 2.1.72 if that has something to do with it.

It would only work for me without the message.

Ah yes, you are correct - in v2.1.72, only_if did not accept a custom message ( .

v2 is quite old - v4.18.47 is current. Consider upgrading :-), there are many other benefits.

1 Like

Thanks for confirming @cwolfe! I will let the Service Manager know so we can plan an upgrade in our Service Roadmap.