Change the AWS account to launch instances with Chef Test Kitchen

The Chef SDK contains Test Kitchen, that can launch server instances to test your Chef cookbooks. Test Kitchen uses the “chef_zero” provisioner to use your workstation as the virtual Chef server. To switch Test Kitchen to launch instances in another AWS account In the .kitchen.yml file update the availability_zone subnet_id aws_ssh_key_id (if different in each account) …

Test Chef cookbooks locally on a virtual workstation

When you use a virtual machine to write your Chef cookbooks you may want to test them locally with Vagrant. This nested virtual machine cannot use a 64 bit operating system, because to run a 64 bit virtual machine, the host computer’s CPU has to provide the CPU Extensions. Currently only physical CPUs can provide …

Test your cookbook in Chef Test Kitchen against multiple versions of the Chef Client

In large environments, during the Chef Client version change, some older servers still run the prior version of the Chef Client, the newly created servers launch with the new version of the Chef Client. It is very important to test your cookbooks with the old and the new versions of Chef Client. To specify the …

Chef exit codes

Chef uses the standard RFC 062 exit codes. In your .kitchen.yml file, you can supply an array of exit codes in the “retry_on_exit_code” option to retry the operation in case the Chef script execution is interrupted. The usual values are retry_on_exit_code: # An array of exit codes that can indicate that kitchen should retry the converge …

FATAL: Chef::Exceptions::Reboot: Rebooting server at a recipe’s request.

When your Chef recipe requests a reboot using the “reboot” Chef resource, the output window shows an error message: Chef Client finished, …/… resources updated in … seconds […] WARN: Rebooting server at a recipe’s request. Details: {:delay_mins=>1, :reason=>”…”, :timestamp=>…, :requested_by=>”…”} Running handlers: […] ERROR: Running exception handlers Running handlers complete […] ERROR: Exception handlers complete Chef …

Unable to satisfy constraints on package

When you make a change to the version restrictions in the metadata.rb file and execute berks install in your Chef cookbook directory, you may get the error message: Unable to satisfy constraints on package … due to solution constraint (…). Solution constraints that may result in a constraint on …: [(…)], [(…) -> (…)] Demand that …

Skip steps in an InSpec integration test based on Chef attribute values

To speed up the test of some complex recipes, I use an attribute to skip certain long-running installations when I only need to test the rest of the recipe. We will pass Chef Attribute values into an InSpec test using environment variables. Declare an attribute in the atrributes.rb file with a safe default value, to allow the …

Waiting for SSH service on …:22, retrying in 3 seconds

When you try to launch a new EC2 instance in AWS using Chef Test Kitchen and the process times out with the message:   Waiting for SSH service on …:22, retrying in 3 seconds $$$$$$ [SSH] connection failed, terminating (#<Net::SSH::AuthenticationFailed: Authentication failed for user …@…>) >>>>>> ——Exception——- >>>>>> Class: Kitchen::ActionFailed >>>>>> Message: 1 actions failed. …

Failed to complete #create action: [undefined method `version’ for nil:NilClass] on …

When you execute kitchen converge to launch an EC2 instance in AWS with Chef Test Kitchen, you get the error message: >>>>> ——Exception——- >>>>>> Class: Kitchen::ActionFailed >>>>>> Message: 1 actions failed. >>>>>> Failed to complete #create action: [undefined method `version’ for nil:NilClass] on … >>>>>> ———————- >>>>>> Please see .kitchen/logs/kitchen.log for more details >>>>>> Also …

Could not load the ‘ec2’ driver from the load path

When you execute kitchen list and the driver in your .kitchen file is “ec2“, the following error message appears: >>>> ——Exception——- >>>>>> Class: Kitchen::ClientError >>>>>> Message: Could not load the ‘ec2’ driver from the load path. Please ensure that your driver is installed as a gem or included in your Gemfile if using Bundler. >>>>>> ———————- …