How to limit InSpec test to a specific OS Version
Asked Answered
W

2

8

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.

Weisbart answered 30/9, 2016 at 17:49 Comment(0)
D
7

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).

Donal answered 1/10, 2016 at 3:28 Comment(0)
C
5

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/

Conics answered 3/8, 2018 at 16:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.