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.

StephenKing
  • 36,187
  • 11
  • 83
  • 112
Kenneth Baltrinic
  • 2,941
  • 2
  • 28
  • 45

2 Answers2

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

coderanger
  • 52,400
  • 4
  • 52
  • 75
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/

james.garriss
  • 12,959
  • 7
  • 83
  • 96