This cookbook has been used in cloud_init_sample repo.
Expecting the readers should have basic understanding Chef cookbooks and related development experience.
Chef developers or teams looking to implement Chef in-spec script
Developers/testers looking to implement Chef Test Kitchen in real-time using AWS EC2 VM
.
- Set a hostname on operating system level
- Install a package called
my-monitoring-agent
. Assume that the package repository is already configured - Set the hostname in the configuration of the monitoring agent. Config file located at
/etc/mon-agent/agent.conf
- Ensure that the two users,
alice
andbob
, exist and are part of the groupmy-staff
It has inspec test cases to verify the cookbook functionality.
The inspec test will be run inside a AWS EC2 VM, triggered via Chef Test Kitchen.
-
AWS Cloud Account
-
AWS (.pem) keypair should be pre-generated and available already (Value to be used in kitchen.yml driver section)
-
Transfer the pem file into
~/.ssh path
(file should have 600 mode). -
Install
ChefDK
. -
Install the AWS command line tools.
-
Run
aws configure
. This will set up your AWS credentials for both the AWS CLI tools and kitchen-ec2. -
Checkout the
cloud_init
cookbook repo -
Perform below changes in kitchen.yml sections:
driver:
name: ec2
aws_ssh_key_id: "name_of_pem_file_"
region: us-west-2
transport:
username: ubuntu
ssh_key: ~/.ssh/gs-ubuntu-key.pem
Note: Since we are creating Ubuntu instance, user-name should be "ubuntu", otherwise use "ec2-user"
-
Unit test command:
chef exec rspec spec/
-
Linting and syntax check:
chef exec cookstyle
-
Create test vm :
chef exec kitchen create
-
Execute cookbook in test vm:
chef exec kitchen converge
-
Run the inspec test cases in test vm:
chef exec kitchen verify
-
Cleanup the test vm to save costs:
chef exec kitchen destroy
-
End-to-end test run, which includes all the above commands:
chef exec kitchen test
In general, use the kitchen test
subcommand to verify the end-to-end quality of a cookbook.
Use the subcommands kitchen converge
and kitchen verify
during the normal the day-to-day development of a cookbook
Kitchen EC2 Github