Chef on Amazon Linux
First of all create one Linux machine in AWS.
Connect to Linux EC2 Instance through Putty.
Download the Private key of the instance using PuttyGen
Get access to the terminal using the downloaded private key.
Switch to the root user.
sudo su
Update Server Packages.
yum update -y
Download and Install the chef package
packages.chef.io/files/stable/chef-workstat..
wget https://packages.chef.io/files/stable/chef-workstation/20.7.96/el/7/chef-workstation-20.7.96-1.el7.x86_64.rpm
Verify the chef package and Version.
to list the downloaded contain
ls
Install the Chef workstation
for Amazon Linux - chef-workstation-23.3.1030-1.el7.x86_64.rpm
yum install <workstation-name>
Verify the version
chef-v
How to create a cookbook ?
Once we installed the Chef workstation, we need to create the directory called Cookbooks, which will have as many cookbooks with recipes.
Create a directory called cookbooks
mkdir cookbooks
To create a cookbook, go inside the cookbooks directory and generate the cookbook
cd cookbooks
Generating the cookbook,
chef generate cookbook <cookbook-name>
Output- Cookbook created successfully.
To create the recipes we have to go inside created cookbook directory and generate the cookbook.
cd cookbook-name
Generating the recipe,
chef generate recipe <recipe-name>
Output- Recipe created successfully.
To build recipes go to the cookbooks directory. Open the recipe using
vi
command.vi cookbook-name/recipes/<recipe-name.rb>
Now create a file using the Chef recipe, by editing the recipe.
Press i to enter text in file.
Press esc, and type :wq to save and exit the file.
To check Ruby scripting, with output syntax Ok or Not,
chef exec ruby -c cookbook-name/recipes/<recipe-name.rb>
Execute the recipe
chef-client -zr "recipe[cookbook-name::recipe-name]"
Output- myfile is created with the content.
Subscribe to my newsletter
Read articles from Apurva Rajmane directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by