2016-09-22 12:43:57 +00:00
---
title: About the os Resource
2018-02-16 00:28:15 +00:00
platform: os
2016-09-22 12:43:57 +00:00
---
# os
2019-04-26 18:24:29 +00:00
Use the `os` Chef InSpec audit resource to test the platform on which the system is running.
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
<br>
2018-08-09 12:34:49 +00:00
## Availability
### Installation
2019-04-26 18:24:29 +00:00
This resource is distributed along with Chef InSpec itself. You can use it automatically.
2018-08-09 12:34:49 +00:00
### Version
This resource first became available in v1.0.0 of InSpec.
2016-09-27 19:03:23 +00:00
## Syntax
2016-09-22 12:43:57 +00:00
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:
2018-03-12 17:02:48 +00:00
describe os.family do
2017-10-06 13:44:32 +00:00
it { should eq 'platform_family_name' }
2016-09-22 12:43:57 +00:00
end
2017-10-06 13:44:32 +00:00
* `'platform_family_name'` (a string) is one of `aix`, `bsd`, `darwin`, `debian`, `hpux`, `linux`, `redhat`, `solaris`, `suse`, `unix`, or `windows`
2016-09-22 12:43:57 +00:00
2017-10-06 13:44:32 +00:00
The parameters available to `os` are:
2016-09-22 12:43:57 +00:00
2017-10-06 13:44:32 +00:00
* `:name` - the operating system name, such as `centos`
* `:family` - the operating system family, such as `redhat`
* `:release` - the version of the operating system, such as `7.3.1611`
* `:arch` - the architecture of the operating system, such as `x86_64`
2017-10-03 21:35:10 +00:00
<br>
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
## Examples
2016-09-22 12:43:57 +00:00
2019-04-26 18:24:29 +00:00
The following examples show how to use this Chef InSpec audit resource.
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
### Test for RedHat
2016-09-22 12:43:57 +00:00
2018-03-12 17:02:48 +00:00
describe os.family do
2017-10-03 21:35:10 +00:00
it { should eq 'redhat' }
end
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
### Test for Ubuntu
2016-09-22 12:43:57 +00:00
2018-03-12 17:02:48 +00:00
describe os.family do
2017-10-03 21:35:10 +00:00
it { should eq 'debian' }
end
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
### Test for Microsoft Windows
2016-09-22 12:43:57 +00:00
2018-03-12 17:02:48 +00:00
describe os.family do
2017-10-03 21:35:10 +00:00
it { should eq 'windows' }
end
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
<br>
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
## Matchers
2016-09-22 12:43:57 +00:00
2018-02-16 03:07:18 +00:00
For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
2016-09-22 12:43:57 +00:00
2018-02-16 02:34:11 +00:00
### os.family? Helpers
2016-09-22 12:43:57 +00:00
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)
2017-01-09 00:59:02 +00:00
* `redhat?` (including CentOS)
2016-09-22 12:43:57 +00:00
* `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
2018-03-12 17:02:48 +00:00
### os.family names
2016-09-22 12:43:57 +00:00
2018-03-12 17:02:48 +00:00
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:
2016-09-22 12:43:57 +00:00
2018-03-12 17:02:48 +00:00
* `aix`
* `bsd` For platforms that are part of the Berkeley OS family `darwin`, `freebsd`, `netbsd`, and `openbsd`.
* `debian`
* `hpux`
* `linux`. For platforms that are part of the Linux family `alpine`, `amazon`, `arch`, `coreos`, `exherbo`, `fedora`, `gentoo`, and `slackware`.
* `redhat`. For platforms that are part of the Redhat family `centos`.
* `solaris`. For platforms that are part of the Solaris family `nexentacore`, `omnios`, `openindiana`, `opensolaris`, and `smartos`.
* `suse`
* `unix`
* `windows`
2016-09-22 12:43:57 +00:00
For example, both of the following tests should have the same result:
2018-06-06 18:10:48 +00:00
```ruby
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
```