2016-09-22 14:43:57 +02:00
|
|
|
---
|
|
|
|
title: About the pip Resource
|
2018-02-15 18:28:15 -06:00
|
|
|
platform: os
|
2016-09-22 14:43:57 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
# pip
|
|
|
|
|
|
|
|
Use the `pip` InSpec audit resource to test packages that are installed using the Python PIP installer.
|
|
|
|
|
2017-10-03 14:35:10 -07:00
|
|
|
<br>
|
|
|
|
|
2016-09-27 12:03:23 -07:00
|
|
|
## Syntax
|
2016-09-22 14:43:57 +02:00
|
|
|
|
|
|
|
A `pip` resource block declares a package and (optionally) a package version:
|
|
|
|
|
2016-11-19 17:37:24 -08:00
|
|
|
describe pip('package_name') do
|
2016-09-22 14:43:57 +02:00
|
|
|
it { should be_installed }
|
|
|
|
end
|
|
|
|
|
|
|
|
where
|
|
|
|
|
2016-11-19 17:37:24 -08:00
|
|
|
* `'package_name'` is the name of the package, such as `'Jinja2'`
|
|
|
|
* `be_installed` tests to see if the package described above is installed
|
2016-09-22 14:43:57 +02:00
|
|
|
|
2017-10-03 14:35:10 -07:00
|
|
|
<br>
|
2016-09-22 14:43:57 +02:00
|
|
|
|
2017-10-03 14:35:10 -07:00
|
|
|
## Examples
|
2016-09-22 14:43:57 +02:00
|
|
|
|
2017-10-03 14:35:10 -07:00
|
|
|
The following examples show how to use this InSpec audit resource.
|
2016-09-22 14:43:57 +02:00
|
|
|
|
2017-10-03 14:35:10 -07:00
|
|
|
### Test if Jinja2 is installed on the system
|
2016-09-22 14:43:57 +02:00
|
|
|
|
2017-10-03 14:35:10 -07:00
|
|
|
describe pip('Jinja2') do
|
|
|
|
it { should be_installed }
|
|
|
|
end
|
2016-09-22 14:43:57 +02:00
|
|
|
|
2017-10-03 14:35:10 -07:00
|
|
|
### Test if Jinja2 2.8 is installed on the system
|
2016-09-22 14:43:57 +02:00
|
|
|
|
2017-10-03 14:35:10 -07:00
|
|
|
describe pip('Jinja2') do
|
|
|
|
it { should be_installed }
|
|
|
|
its('version') { should eq '2.8' }
|
|
|
|
end
|
2016-09-22 14:43:57 +02:00
|
|
|
|
2018-01-19 23:03:00 +01:00
|
|
|
### Test packages installed into a non-default location (e.g. virtualenv) by passing a custom path to pip executable
|
|
|
|
|
|
|
|
describe pip('Jinja2', '/path/to/bin/pip') do
|
|
|
|
it { should be_installed }
|
|
|
|
its('version') { should eq '2.8' }
|
|
|
|
end
|
|
|
|
|
2017-10-03 14:35:10 -07:00
|
|
|
<br>
|
2016-09-22 14:43:57 +02:00
|
|
|
|
2017-10-03 14:35:10 -07:00
|
|
|
## Matchers
|
2016-09-22 14:43:57 +02:00
|
|
|
|
2018-02-15 19:07:18 -08:00
|
|
|
For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
2016-09-22 14:43:57 +02:00
|
|
|
|
2017-10-03 14:35:10 -07:00
|
|
|
### be_installed
|
2016-09-22 14:43:57 +02:00
|
|
|
|
2017-10-03 14:35:10 -07:00
|
|
|
The `be_installed` matcher tests if the named package is installed on the system:
|
2016-09-22 14:43:57 +02:00
|
|
|
|
2017-10-03 14:35:10 -07:00
|
|
|
it { should be_installed }
|
2016-09-22 14:43:57 +02:00
|
|
|
|
2016-09-27 12:03:23 -07:00
|
|
|
### version
|
2016-09-22 14:43:57 +02:00
|
|
|
|
|
|
|
The `version` matcher tests if the named package version is on the system:
|
|
|
|
|
|
|
|
its('version') { should eq '1.2.3' }
|