docwhat's avatardocwhat's blog

Setting your environment in test-kitchen

When using test-kitchen it may be necessary to set the environment of your nodes.

You can do with by changing your .kitchen.yml file. In my example, I’ll show it at the root, but they can be set on a per-suite level as well, which is handy to test different environments.

For chef-solo:

driver:
  name: vagrant

provisioner:
  name: chef_solo
  environments_path: test/environments
  solo_rb:
    environment: kitchen

# etc...

For chef-zero:

driver:
  name: vagrant

provisioner:
  name: chef_zero
  environments_path: test/environments
  client_rb:
    environment: kitchen

# etc...

Notes:

  • You must use .json files for the environment files with chef-zero. It doesn’t understand .rb environment files.
  • chef-zero uses client_rb whereas chef-solo uses solo_rb. Why? Because chef-solo isn’t a full chef server.

Example environment .json file:

{
  "name": "myenvironment",
  "description": "My Chef environment",
  "cookbook_versions": {},
  "json_class": "Chef::Environment",
  "chef_type": "environment",
  "default_attributes": {},
  "override_attributes": {}
}

Comments

Gravatar for munna
Munna

How can this be accessed in the script?

Gravatar for docwhat
docwhat

I’m not sure I understand. Which script?

Gravatar for faja
faja

Hi there,

how can I specify environment on a per-suite level? Adding:

client_rb:
    environment: kitchen

to suite section doesn’t work (environment is still _default).

Gravatar for faja
faja

Ok, found it :)

suites:
  -  name: dev
     provisioner:
       client_rb:
         environment: dev
Gravatar for chaim
Chaim

Is there a way to do this with chef_solo and a node.json file with the run_list in the node.json file?

Gravatar for docwhat
docwhat

I didn’t even know you could use node .json files. Do you have more info about it?

Gravatar for chaim
Chaim

What I’ve been doing, without test-kitchen, is running chef-solo on command line like this:

chef-solo -j nodes/$(hostname).json

I have a JSON file for each of my nodes and just call it with the --json-attributes (-j) option.

I’d love to be able to implement that in chef-kitchen.

I only use chef-solo and have no Chef Server.

Gravatar for docwhat
docwhat

No. Chef doesn’t allow that.

Submit a Comment

docwhat

The personal blog of Christian Höltje.
docwhat docwhat contact