os resource
Use the os
Chef InSpec audit resource to test the platform on which the system is running.
Availability
Installation
This resource is distributed with Chef InSpec and is automatically available for use.
Version
This resource first became available in v1.0.0 of InSpec.
Syntax
An os
resource block declares the platform to be tested. The platform may specified via matcher or control block name. For example, using a matcher:
describe os.family do
it { should eq 'platform_family_name' }
end
'platform_family_name'
(a string) is one ofaix
,bsd
,darwin
,debian
,hpux
,linux
,redhat
,solaris
,suse
,unix
, orwindows
The parameters available to os
are:
:name
- the operating system name, such ascentos
:family
- the operating system family, such asredhat
:release
- the version of the operating system, such as7.3.1611
:arch
- the architecture of the operating system, such asx86_64
Examples
The following examples show how to use this Chef InSpec audit resource.
Test for RedHat
describe os.family do
it { should eq 'redhat' }
end
Test for Ubuntu
describe os.family do
it { should eq 'debian' }
end
Test for Microsoft Windows
describe os.family do
it { should eq 'windows' }
end
Matchers
For a full list of available matchers, please visit our matchers page.
os.family? Helpers
The os
audit resource includes a collection of helpers that enable more granular testing of platforms, platform names, architectures, and releases. Use any of the following platform-specific helpers to test for specific platforms:
aix?
bsd?
(including Darwin, FreeBSD, NetBSD, and OpenBSD)darwin?
debian?
hpux?
linux?
(including Alpine Linux, Amazon Linux, ArchLinux, CoreOS, Exherbo, Fedora, Gentoo, and Slackware)redhat?
(including CentOS)solaris?
(including Nexenta Core, OmniOS, Open Indiana, Solaris Open, and SmartOS)suse?
unix?
windows?
For example, to test for Darwin use:
describe os.bsd? do
it { should eq true }
end
To test for Windows use:
describe os.windows? do
it { should eq true }
end
and to test for Redhat use:
describe os.redhat? do
it { should eq true }
end
Use the following helpers to test for operating system names, releases, and architectures:
describe os.name do
it { should eq 'foo' }
end
describe os.release do
it { should eq 'foo' }
end
describe os.arch do
it { should eq 'foo' }
end
os.family names
Use os.family
to enable more granular testing of platforms, platform names, architectures, and releases. Use any of the following platform-specific names to test for specific platforms:
aix
bsd
For platforms that are part of the Berkeley OS familydarwin
,freebsd
,netbsd
, andopenbsd
.debian
hpux
linux
. For platforms that are part of the Linux familyalpine
,amazon
,arch
,coreos
,exherbo
,fedora
,gentoo
, andslackware
.redhat
. For platforms that are part of the Redhat familycentos
.solaris
. For platforms that are part of the Solaris familynexentacore
,omnios
,openindiana
,opensolaris
, andsmartos
.suse
unix
windows
For example, both of the following tests should have the same result:
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
if os.debian?
describe port(69) do
its('processes') { should include 'in.tftpd' }
end
elsif os.redhat?
describe port(69) do
its('processes') { should include 'xinetd' }
end
end