2017-10-25 14:01:26 +00:00
|
|
|
---
|
|
|
|
title: About the cpan Resource
|
2018-02-16 00:28:15 +00:00
|
|
|
platform: linux
|
2017-10-25 14:01:26 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# cpan
|
|
|
|
|
2019-04-26 18:24:29 +00:00
|
|
|
Use the `cpan` Chef InSpec audit resource to test Perl modules that are installed by system packages or the CPAN installer.
|
2017-10-25 14:01:26 +00:00
|
|
|
|
2018-02-02 12:35:50 +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.43.5 of InSpec.
|
|
|
|
|
2017-10-25 14:01:26 +00:00
|
|
|
## Syntax
|
|
|
|
|
|
|
|
A `cpan` resource block declares a package and (optionally) a package version:
|
|
|
|
|
|
|
|
describe cpan('package_name') do
|
|
|
|
it { should be_installed }
|
|
|
|
end
|
|
|
|
|
|
|
|
where
|
|
|
|
|
|
|
|
* `'package_name'` is the name of the package, such as `'DBD::Pg'`
|
|
|
|
* `be_installed` tests to see if the package described above is installed
|
|
|
|
|
2018-02-02 12:35:50 +00:00
|
|
|
<br>
|
2017-10-25 14:01:26 +00:00
|
|
|
|
2018-02-15 14:33:22 +00:00
|
|
|
## Resource Parameters
|
2017-10-25 14:01:26 +00:00
|
|
|
|
2018-02-02 12:35:50 +00:00
|
|
|
This resource uses package names and perl library paths as resource parameters.
|
2017-10-25 14:01:26 +00:00
|
|
|
|
2018-02-02 12:35:50 +00:00
|
|
|
<br>
|
2017-10-25 14:01:26 +00:00
|
|
|
|
2018-02-02 12:35:50 +00:00
|
|
|
## Resource Parameter Examples
|
2017-10-25 14:01:26 +00:00
|
|
|
|
|
|
|
### Test if DBD::Pg is installed on the system
|
|
|
|
|
|
|
|
describe cpan('DBD:Pg') do
|
|
|
|
it { should be_installed }
|
|
|
|
end
|
|
|
|
|
|
|
|
### Test if DBD::Pg 3.7.0 is installed on the system
|
|
|
|
|
|
|
|
describe cpan('DBD::Pg') do
|
|
|
|
it { should be_installed }
|
|
|
|
its('version') { should eq '3.7.0' }
|
|
|
|
end
|
2018-02-16 00:28:15 +00:00
|
|
|
|
2017-10-25 14:01:26 +00:00
|
|
|
### Test if DBD::Pg is installed within a custom PERL5LIB path on the system
|
|
|
|
|
2018-02-02 12:35:50 +00:00
|
|
|
Hint: You can pass multiple paths separated with a colon
|
|
|
|
`/path/to/perl5/lib:/usr/share/perl5/vendor_perl/lib/perl5`
|
2017-10-25 14:01:26 +00:00
|
|
|
|
|
|
|
describe cpan('DBD::Pg', '/home/jdoe/perl5/lib/perl5') do
|
|
|
|
it { should be_installed }
|
|
|
|
end
|
2018-02-02 12:35:50 +00:00
|
|
|
|
|
|
|
<br>
|
|
|
|
|
|
|
|
## Property Examples
|
|
|
|
|
2019-04-26 18:24:29 +00:00
|
|
|
The following examples show how to use this Chef InSpec audit resource.
|
2018-02-02 12:35:50 +00:00
|
|
|
|
|
|
|
### version
|
|
|
|
|
|
|
|
The `version` property tests if the named package version is on the system:
|
|
|
|
|
|
|
|
its('version') { should eq '1.2.3' }
|
|
|
|
|
|
|
|
<br>
|
|
|
|
|
|
|
|
## Matchers
|
|
|
|
|
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/).
|
2018-02-02 12:35:50 +00:00
|
|
|
|
|
|
|
### be_installed
|
|
|
|
|
|
|
|
The `be_installed` matcher tests if the named package is installed on the system:
|
|
|
|
|
2018-02-16 00:28:15 +00:00
|
|
|
it { should be_installed }
|