DevOps Classroom Series – 15/Apr/2020

Test Kitchen

  • Test Kitchen is a tool developed to test the chef-cookbooks on multiple platforms. For official docs refer here

  • For this test kitchen has a component which is called as driver, which enables kitchen to test in various platforms such as

    • Vagrant
    • Virtual Box
    • VM Ware
    • Hyper V
    • AWS
    • Azure
    • Google Cloud
    • Docker
  • In this series we will be using AWS and Azure

Test Kitchen with AWS

  • Kitchen with AWS Driver is what we would like to use.
  • Generate a cookbook for test kitchen demo with AWS
chef generate cookbook -b kitchenawsdemo
  • Lets write a very simple resource to create a file in ‘/tmp/test.txt’. I will be using file as mentioned in the documentation in the Default.rb
# Cookbook:: kitchenawsdemo
# Recipe:: default
# Copyright:: 2020, The Authors, All Rights Reserved.
file '/tmp/test.txt' do
    content 'hello im testing'
    action :create
  • Now i want to test this cookbook on a Linux Machine in AWS Cloud, for this we have to look at two things
    • Use Kitchen.yml file generated along with cookbook to configure the environment (AWS) to test Preview
    • Connecting to AWS: Refer to AWS Preparation Section in here Preview
    • We will be using a driver called as ec2 refer here
    • Install AWS CLI from here
    • Make a note of
      • region
      • az
      • VPC-id
      • subnet-id
      • security group
      • Image id: Preview Preview
    • My list looks like
    "SubnetId": "subnet-89fb32ee",
    "VpcId": "vpc-4366ce24"
    region: us-west-2
    az: "us-west-2b"
    image-id:  ami-0d1cd67c26f5fca19
    username: "ubuntu"
    keypair: chef.pem
    security group: sg-0fde1a94ae5592488 (chefclient)
    • Kitchen.yml file looks as shown below
    name: ec2
    aws_ssh_key_id: chef
    region: us-west-2
    availability_zone: us-west-2b
    subnet_id: subnet-89fb32ee
    instance_type: t2.micro
    image_id: 'ami-0d1cd67c26f5fca19'
    security_group_ids: ["sg-0fde1a94ae5592488"]
    ## The forwarded_port port feature lets you connect to ports on the VM guest via
    ## localhost on the host.
    ## see also:
    #  network:
    #    - ["forwarded_port", {guest: 80, host: 8080}]
    name: chef_zero
    # You may wish to disable always updating cookbooks in CI or other testing environments.
    # For example:
    #   always_update_cookbooks: <%= !ENV['CI'] %>
    always_update_cookbooks: true
    ## product_name and product_version specifies a specific Chef product and version to install.
    ## see the Chef documentation for more details:
    #  product_name: chef
    #  product_version: 15
    ssh_key: "./chef.pem"
    connection_timeout: 10
    connection_retries: 3
    username: ubuntu
    name: inspec
    - name: ubuntu-18.04
    # - name: centos-7
    - name: default
        - recipe[kitchenawsdemo::default]
            - test/integration/default
    • Now cd into the cookbook folder from terminal and execute the following commands
    kitchen list
    kitchen create
    kitchen list
    • Make changes in the recipe and execute the kitchen converge
    • Once you are confident with your changes, then delete the environment using kitchen destroy


  • We need to learn to work with multiple platforms if required.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin