2016-09-22 12:43:57 +00:00
|
|
|
---
|
|
|
|
title: About the yaml Resource
|
2018-02-16 00:28:15 +00:00
|
|
|
platform: os
|
2016-09-22 12:43:57 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# yaml
|
|
|
|
|
|
|
|
Use the `yaml` InSpec audit resource to test configuration data in a Yaml file.
|
|
|
|
|
2017-10-03 21:35:10 +00:00
|
|
|
<br>
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
## Syntax
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
A `yaml` resource block declares the configuration data to be tested. Assume the following Yaml file:
|
|
|
|
|
|
|
|
name: foo
|
|
|
|
array:
|
|
|
|
- zero
|
|
|
|
- one
|
|
|
|
|
|
|
|
This file can be queried using:
|
|
|
|
|
2017-05-01 21:16:00 +00:00
|
|
|
describe yaml('filename.yml') do
|
2016-09-22 12:43:57 +00:00
|
|
|
its('name') { should eq 'foo' }
|
|
|
|
its(['array', 1]) { should eq 'one' }
|
|
|
|
end
|
|
|
|
|
|
|
|
where
|
|
|
|
|
|
|
|
* `name` is a configuration setting in a Yaml file
|
|
|
|
* `should eq 'foo'` tests a value of `name` as read from a Yaml file versus the value declared in the test
|
|
|
|
|
2017-05-01 21:16:00 +00:00
|
|
|
Like the `json` resource, the `yaml` resource can read a file, run a command, or accept content inline:
|
|
|
|
|
|
|
|
describe yaml('config.yaml') do
|
|
|
|
its(['driver', 'name']) { should eq 'vagrant' }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe yaml({ command: 'retrieve_data.py --yaml' }) do
|
|
|
|
its('state') { should eq 'open' }
|
|
|
|
end
|
|
|
|
|
2018-03-28 17:20:56 +00:00
|
|
|
describe yaml({ content: "\"key1: value1\nkey2: value2\"" }) do
|
2017-05-01 21:16:00 +00:00
|
|
|
its('key2') { should cmp 'value2' }
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
2017-10-03 21:35:10 +00:00
|
|
|
The following examples show how to use this InSpec audit resource.
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2017-10-03 21:35:10 +00:00
|
|
|
### Test a kitchen.yml file driver
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2017-10-03 21:35:10 +00:00
|
|
|
describe yaml('.kitchen.yaml') do
|
2018-03-28 17:20:56 +00:00
|
|
|
its(['driver','name']) { should eq('vagrant') }
|
2017-10-03 21:35:10 +00:00
|
|
|
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
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
### name
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
The `name` matcher tests the value of `name` as read from a Yaml file versus the value declared in the test:
|
|
|
|
|
|
|
|
its('name') { should eq 'foo' }
|