Chef on Amazon Linux

Apurva RajmaneApurva Rajmane
2 min read
  1. First of all create one Linux machine in AWS.

  2. 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.

  3. Switch to the root user.

    sudo su

  4. Update Server Packages.

    yum update -y

  5. 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

  6. Verify the chef package and Version.

    • to list the downloaded contain

      ls

  7. Install the Chef workstation

    for Amazon Linux - chef-workstation-23.3.1030-1.el7.x86_64.rpm

    yum install <workstation-name>

  8. 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.

  1. Create a directory called cookbooks

    mkdir cookbooks

  2. 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.

  3. 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.

  4. To build recipes go to the cookbooks directory. Open the recipe using vi command.

    vi cookbook-name/recipes/<recipe-name.rb>

  5. 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.

  6. To check Ruby scripting, with output syntax Ok or Not,

    chef exec ruby -c cookbook-name/recipes/<recipe-name.rb>

  7. Execute the recipe

    chef-client -zr "recipe[cookbook-name::recipe-name]"

    Output- myfile is created with the content.

0
Subscribe to my newsletter

Read articles from Apurva Rajmane directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Apurva Rajmane
Apurva Rajmane