2016-09-22 12:43:57 +00:00
|
|
|
---
|
|
|
|
title: About the ini Resource
|
2018-02-16 00:28:15 +00:00
|
|
|
platform: os
|
2016-09-22 12:43:57 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# ini
|
|
|
|
|
2019-04-26 18:24:29 +00:00
|
|
|
Use the `ini` Chef InSpec audit resource to test settings in an INI file.
|
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 `ini` resource block declares the configuration settings to be tested:
|
|
|
|
|
|
|
|
describe ini('path') do
|
|
|
|
its('setting_name') { should eq 'value' }
|
|
|
|
end
|
|
|
|
|
|
|
|
where
|
|
|
|
|
2017-11-20 12:08:51 +00:00
|
|
|
* `'setting_name'` is a setting key defined in the INI file
|
2016-09-22 12:43:57 +00:00
|
|
|
* `('path')` is the path to the INI file
|
|
|
|
* `{ should eq 'value' }` is the value that is expected
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
describe ini('path/to/ini_file.ini') do
|
|
|
|
its('port') { should eq '143' }
|
|
|
|
its('server') { should eq '192.0.2.62' }
|
|
|
|
end
|
|
|
|
|
2017-11-20 12:08:51 +00:00
|
|
|
Settings inside of sections, such as the following:
|
|
|
|
|
|
|
|
[section_name]
|
|
|
|
setting_name = 123
|
|
|
|
|
|
|
|
... can be retrieved by prefixing the setting_name with the section.
|
|
|
|
|
|
|
|
its('section_name.setting_name') { should cmp 123 }
|
|
|
|
|
|
|
|
In the event a section or setting name has a period in it, the alternate syntax can be used:
|
|
|
|
|
|
|
|
its(['section.with.a.dot.in.it', 'setting.name.with.dots']) { should cmp 'lotsadots' }
|
|
|
|
|
2017-10-03 21:35:10 +00:00
|
|
|
<br>
|
2018-02-16 02:34:11 +00:00
|
|
|
|
2018-02-15 14:33:22 +00:00
|
|
|
## Properties
|
2018-02-08 21:43:21 +00:00
|
|
|
|
2018-02-16 00:28:15 +00:00
|
|
|
This resource supports any of the settings listed in an INI file as properties.
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2018-02-16 02:34:11 +00:00
|
|
|
<br>
|
|
|
|
|
2016-09-27 19:03:23 +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
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
### Test SMTP settings in a PHP INI file
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
For example, a PHP INI file located at contains the following settings:
|
|
|
|
|
2018-01-17 19:41:33 +00:00
|
|
|
[mail function]
|
|
|
|
SMTP = smtp.gmail.com
|
|
|
|
smtp_port = 465
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
and can be tested like this:
|
|
|
|
|
2018-01-17 19:41:33 +00:00
|
|
|
describe ini('/etc/php5/apache2/php.ini') do
|
|
|
|
its('mail function.smtp_port') { should eq('465') }
|
2016-09-22 12:43:57 +00:00
|
|
|
end
|
2017-10-03 21:35:10 +00:00
|
|
|
|
|
|
|
<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/).
|