Chef cookbook for installing lamp on ubuntu server
- Manual Steps for installing lamp on ubuntu 18
- Refer Here for the documentation
- Summary of manual steps
sudo apt update
sudo apt install apache2 -y
sudo apt install php libapache2-mod-php php-mysql php-cli -y
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
-
Once we execute these steps and navigate to
http://<public-ip>/info.php
-
Now Generate the cookbook
chef generate cookbook lampserver -b
-
Now we need to convert each of the above mentioned manual step into a resource in a recipe file
-
We already have a recipe file in recipes folder called as default.rb
-
Refer Here for the cookbook created in the class and Refer Here for the recipe
-
We have a cookbook ready, to test this cookbook
- Create a test node and bootstrap it to the chef server (manage.chef.io)
- Add recipe to run_list on test node and check whether it is working or not
-
When we run the chef-client on the test node we get the following result

-
Problems with the test node creation process
- Bootstrapping test nodes every time
- If my cookbook has to work on different flavours on Linux Creating VMs manually and checking the cookbook execution manually will be difficult.
- Changes in the cook might lead to new versions uploaded to the chef server
-
We need some kind of tool,
- Which will automatically create the VM and run the recipe in the VM
- Lets us verify the results
- Also works with various cloud/virtual environments without need of chef server
- No Need to change cookbook versions to verify
-
In Chef we have a toolkit called as test-kitchen which can exactly do the above steps
Configuring Test Kitchen to Work with AWS
- Test Kitchen can be used to automatically test cookbooks on different platforms
- To work with test kitchen
- AWS Account
- YAML Refer Here
- Test kitchen can create infrastructure on different virtual environments & for that it uses a driver Refer Here
- To set up a test kitchen Refer Here
- In AWS, we need a user with which test-kitchen can login into AWS account and create ec2 instances for testing. We do this by creating an IAM user
- On the chef workstation, it is recommended to install aws cli Refer Here
- Make a note of
- region
- availability zone
- vpc-id
aws ec2 describe-vpcs --query "Vpcs[0].VpcId"- subnet-id
aws ec2 describe-subnets --filters "Name=availability-zone,Values=us-west-2a" --query "Subnets[0].SubnetId"- security group id
- Add all of the noted information to kitchen.yaml file
- Now execute
kitchen --help
- Now execute
kitchen converge

- Refer Here for the kitchen configuration
Windows Terminal
- Refer Here to install windows terminal.
