Set the environment name in Chef Test Kitchen

To specify the environment name in the .kitchen.yml file

Create a JSON environment file. Chef Zero used by Test Kitchen does not understand YAML or Ruby, we need to use JSON.

  • In your cookbook’s root directory create a directory for environment files
mkdir environments
  • Create the myenv.json environment file in the environments directory.
{
    "name": "myenv",
    "description": "Test environment",
    "chef_type": "environment"
}
  • Specify the environment name in the .kitchen.yml file
provisioner:
  name: chef_zero
  client_rb:
    environment: "myenv"
  • Set the environment file location in the suite
suites:
  - name: default_envtest
    environments_path: "environments"

The node.chef_environment value will be “myenv” during the Test Kitchen run.

Leave a comment

Your email address will not be published. Required fields are marked *