2016-09-22 12:43:57 +00:00
---
title: About the package Resource
---
# package
Use the `package` InSpec audit resource to test if the named package and/or package version is installed on the system.
2016-09-27 19:03:23 +00:00
## Syntax
2016-09-22 12:43:57 +00:00
A `package` resource block declares a package and (optionally) a package version:
describe package('name') do
it { should be_installed }
end
where
* `('name')` must specify the name of a package, such as `'nginx'`
* `be_installed` is a valid matcher for this resource
2016-09-27 19:03:23 +00:00
## Matchers
2016-09-22 12:43:57 +00:00
This InSpec audit resource has the following matchers:
2016-09-27 19:03:23 +00:00
### be
2016-09-22 12:43:57 +00:00
<%= partial "/shared/matcher_be" %>
2016-09-27 19:03:23 +00:00
### be_installed
2016-09-22 12:43:57 +00:00
The `be_installed` matcher tests if the named package is installed on the system:
it { should be_installed }
2016-09-27 19:03:23 +00:00
### cmp
2016-09-22 12:43:57 +00:00
<%= partial "/shared/matcher_cmp" %>
2016-09-27 19:03:23 +00:00
### eq
2016-09-22 12:43:57 +00:00
<%= partial "/shared/matcher_eq" %>
2016-09-27 19:03:23 +00:00
### include
2016-09-22 12:43:57 +00:00
<%= partial "/shared/matcher_include" %>
2016-09-27 19:03:23 +00:00
### match
2016-09-22 12:43:57 +00:00
<%= partial "/shared/matcher_match" %>
2016-09-27 19:03:23 +00:00
### version
2016-09-22 12:43:57 +00:00
The `version` matcher tests if the named package version is on the system:
its('version') { should eq '1.2.3' }
2016-09-27 19:03:23 +00:00
## Examples
2016-09-22 12:43:57 +00:00
The following examples show how to use this InSpec audit resource.
2016-09-27 19:03:23 +00:00
### Test if nginx version 1.9.5 is installed
2016-09-22 12:43:57 +00:00
describe package('nginx') do
it { should be_installed }
2016-11-15 16:58:25 +00:00
its('version') { should eq '1.9.5' }
2016-09-22 12:43:57 +00:00
end
2016-09-27 19:03:23 +00:00
### Test that a package is not installed
2016-09-22 12:43:57 +00:00
describe package('some_package') do
it { should_not be_installed }
end
2016-09-27 19:03:23 +00:00
### Test if telnet is installed
2016-09-22 12:43:57 +00:00
describe package('telnetd') do
it { should_not be_installed }
end
describe inetd_conf do
its('telnet') { should eq nil }
end
2016-09-27 19:03:23 +00:00
### Test if ClamAV (an antivirus engine) is installed and running
2016-09-22 12:43:57 +00:00
describe package('clamav') do
it { should be_installed }
its('version') { should eq '0.98.7' }
end
describe service('clamd') do
it { should_not be_enabled }
it { should_not be_installed }
it { should_not be_running }
end
2016-09-27 19:03:23 +00:00
### Verify if Memcached is installed, enabled, and running
2016-09-22 12:43:57 +00:00
Memcached is an in-memory key-value store that helps improve the performance of database-driven websites and can be installed, maintained, and tested using the `memcached` cookbook (maintained by Chef). The following example is from the `memcached` cookbook and shows how to use a combination of the `package`, `service`, and `port` InSpec audit resources to test if Memcached is installed, enabled, and running:
describe package('memcached') do
it { should be_installed }
end
describe service('memcached') do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
describe port(11_211) do
it { should be_listening }
end