Test Kitchen - `kitchen.yml` File
January 5, 2024About 2 min
Understanding the kitchen.yml File
The kitchen.yml file is the primary configuration file for Test Kitchen. It outlines the shared configuration for all your testing environments, platforms, and the testing framework to be used.
Each of the subsequent kitchen files will inherit the shared settings from this file automatlly and merge them with the setting in the child kitchen file.
Example kitchen.yml file
---
verifier:
name: inspec
sudo: true
reporter:
- cli
- json:spec/results/%{platform}_%{suite}.json
inspec_tests:
- name: RedHat 8 STIG v1r12
path: .
input_files:
- kitchen.inputs.yml
<% if ENV['INSPEC_CONTROL'] %>
controls:
- "<%= ENV['INSPEC_CONTROL'] %>"
<% end %>
load_plugins: true
suites:
- name: vanilla
provisioner:
playbook: spec/ansible/roles/ansible-role-rhel-vanilla.yml
- name: hardened
provisioner:
playbook: spec/ansible/roles/ansible-role-rhel-hardened.ymlBreakdown of the kitchen.yml file:
verifier:
name: inspec
sudo: true
reporter:
- cli
- json:spec/results/%{platform}_%{suite}.json
inspec_tests:
- name: RedHat 8 STIG v1r12
path: .
input_files:
- kitchen.inputs.yml
<% if ENV['INSPEC_CONTROL'] %>
controls:
- "<%= ENV['INSPEC_CONTROL'] %>"
<% end %>
load_plugins: trueThis first section configures the verifier, which is the tool that checks if your system is in the desired state. Here, it's using InSpec.
sudo: truemeans that InSpec will run with sudo privileges.reporterspecifies the formats in which the test results will be reported. Here, it's set to report in the command-line interface (cli) and in a JSON file (json:spec/results/%{platform}_%{suite}.json).inspec_testsspecifies the InSpec profiles to run. Here, it's running the "RedHat 8 STIG v1r12" profile located in the current directory (path: .).input_filesspecifies files that contain input variables for the InSpec profile. Here, it's using thekitchen.inputs.ymlfile.- The
controlssection is dynamically set based on theINSPEC_CONTROLenvironment variable. If the variable is set, only the specified control will be run. load_plugins: truemeans that InSpec will load any available plugins.
suites:
- name: vanilla
provisioner:
playbook: spec/ansible/roles/ansible-role-rhel-vanilla.yml
- name: hardened
provisioner:
playbook: spec/ansible/roles/ansible-role-rhel-hardened.ymlThis section defines the test suites. Each suite represents a different configuration to test.
- Each suite has a
nameand aprovisioner. - The
provisionersection specifies the Ansible playbook to use for the suite. Here, it's using theansible-role-rhel-vanilla.ymlplaybook for the "vanilla" suite and theansible-role-rhel-hardened.ymlplaybook for the "hardened" suite.
Environment Variables in kitchen.yml
INSPEC_CONTROL: This variable allows you to specify a single control to run during thebundle exec kitchen verifyphase. This is particularly useful for testing or debugging a specific requirement.
Recap on Kitchen Stages
The workflow of Test Kitchen involves the following steps:
- Create: Test Kitchen uses the driver to create an instance of the platform.
- Converge: Test Kitchen uses the provisioner to apply the infrastructure code to the instance. In this case, it's using Ansible playbooks.
- Verify: Test Kitchen uses the verifier to check if the instance is in the desired state.
- Destroy: Test Kitchen uses the driver to destroy the instance after testing. This is not shown in your file.