Skip to content

Instantly share code, notes, and snippets.

@mohanpedala
Last active December 19, 2017 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohanpedala/b26341b1a6e1fc40ad9b006b6f6bd9d8 to your computer and use it in GitHub Desktop.
Save mohanpedala/b26341b1a6e1fc40ad9b006b6f6bd9d8 to your computer and use it in GitHub Desktop.
Chef-test-kitchen

Test-kitchen setup on aws

Reference doc learn-chef

  1. create a aws account and gather the below details

    a. Create your credentials file b. Note your region and availability zone c. Note your VPC subnet d. Create a security group e. Get the AMI ID for CentOS 7 in your region f. Prepare your key pair file

  2. Download learn_chef_httpd cookbook from github

  3. Create a folder for cookbooks for example

mkdir learn-chef/cookbooks

  1. Clone the learn_chef_cookbook from github

prereq: install git

git clone https://github.com/learn-chef/learn_chef_httpd.git

now change the directory.

cd ~/learn-chef/cookbooks/learn_chef_httpd
  1. Edit the .kitchen.yml file as below
---
driver:
  name: ec2
  aws_ssh_key_id: learn-chef
  region: us-east-1
  availability_zone: b
  subnet_id: subnet-3f22bd15
  instance_type: t2.micro
  image_id: ami-6d1c2007
  security_group_ids: sg-0e08cf75
  retryable_tries: 120

provisioner:
  name: chef_zero

verifier:
  name: inspec

transport:
  ssh_key: /root/.ssh/learn-chef.pem

platforms:
  - name: centos-7.2

suites:
  - name: default
    run_list:
      - recipe[learn_chef_httpd::default]
    verifier:
      inspec_tests:
        - test/smoke/default
    attributes:
replace the following with the values you gathered in the previous part.

aws_ssh_key_id		The name of your EC2 key pair
region			Your AWS region
availability_zone	Your AWS availability zone
subnet_id		Your subnet ID
image_id		Your AMI ID
security_group_ids	Your security group ID
ssh_key			The full path to the private part of your EC2 key pair file

  1. Create the test kitchen instance

To see what's in the kitchen

kitchen list

To create the instance

Kitchen create

Now to see the changes in the kitchen list run it again.

  1. Now apply the learn_chef_httpd cookbook to your test kitchen
kitchen converge
  1. Test Kitchen runs chef-client on the instance. When the chef-client run completes successfully, Test Kitchen exits with exit code 0. Run the following to check the exit code.
echo $?
  1. To see the latest status run the kitchen list
  2. To delete the test kitchen run
kitchen destroy

More reference link1 link2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment