How do I skip a control if another control passes?

I am new to InSpec and I am just wondering if you can use the only_if statement with a control? For example, if its("stdout") { should include "SELINUXTYPE" } fails I want to execute another control. If it passes, I want to skip the next control. How would I do this? The whole test would look something like this:

control "SELinux" do
describe bash("more /etc/selinux/config | grep "SELINUX") do

its("stdout") { should include "SELINUX=targeted" }

**if the above control fails, run this next one. Otherwise, skip it**

its("stdout") { should include "SELINUX=mls" }

end
end

If this is bad practice or if it's just horrendously wrong, let me know. I'm very new to this so I'm all up for learning!

It sounds like you'll want to use the "describe.one" syntax documented here:

https://www.inspec.io/docs/reference/dsl_inspec/

This essentially says "it passes if one of these is true".

1 Like

Yep. This works perfectly. Thank you