We have a cookbook that is used on centos 6 and 7 machines. On 7 it installs the latest version of node, on 6 it installs a specific version of node. Also on 6 it installs certain other packages that we don't install on 7. I am trying to figure out how to write an InSpec tests that will only exectuce/assert that things are in a give state if we are testing a centos 6 box. How do I do this?
Running this with test kitchen.
Chef InSpec works by comparing the actual state of your system with the desired state that you express in easy-to-read and easy-to-write Chef InSpec code. Chef InSpec detects violations and displays findings in the form of a report, but puts you in control of remediation.
Login to the Chef Automate instance via InSpec: inspec compliance login . Upload the profile to Automate: inspec compliance upload <name> . Verify the profile is uploaded correctly: inspec compliance profiles . Run the profile via Automate: inspec compliance exec YOURUSERNAME/<name> .
InSpec is an open source project that lets you define your compliance requirements in a human- and machine-readable language. Once you've codified your requirements, you can run them as automated tests that audit your systems. InSpec provides a local agent, as well as full remote testing support.
You would use the pseudo-resource os
. This exposes a bunch of info about the underlying platform but in this case you want os[:release].start_with?('6')
(and similar for 7
).
InSpec has an os resource. Here's an example of how to use it:
if os.family == 'debian'
describe port(69) do
its('processes') { should include 'in.tftpd' }
end
elsif os.family == 'redhat'
describe port(69) do
its('processes') { should include 'xinetd' }
end
end
You can find more about this resource (and the example above) in the InSpec reference:
https://www.inspec.io/docs/reference/resources/os/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With