Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Chef - Search

In this lab, we will demonstrate an understanding of Chef search in a recipe. First, we are going to install the ChefDK tools on a server, make sure Docker is working, and ensure Git is installed and has some basic configuration. We will then create a cookbook and recipe that utilizes the search function to look for users in a provided data bag. There will be a group created for the users our recipe finds. By the end of this hands-on lab, you will have installed and ChefDK tools, as well as have a working cookbook. We'll perform any testing by using `docker` and `kitchen` commands.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 1h 0m
Published
Clock icon Aug 04, 2020

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    On the Provided Server, Install Version 2.4.17 of the ChefDK Tools

    1. Download and install the 2.4.17 version of ChefDK at the command line.
    2. Once it's installed, make sure Chef uses the correct system locations.
    3. Verify it worked.
  2. Challenge

    Install What docker-ce Requires on This Server

    1. Install yum-utils.
    2. Add the Docker repository.
    3. Install Docker.
    4. Set Docker to start now and on system boot.
    5. Set your user to be able to use Docker without using the sudo command.
    6. Log out and back in again
    7. Check to make sure Docker is running.
      • If you can do that without prefacing it with sudo, you're ready to continue.
  3. Challenge

    Install Git and Set Some Global Defaults for Our User, Email Address, and Editor

    When we use Kitchen, later in the lab, we need Git to be installed and set up with some basic information.

    1. Install Git.
    2. Configure some Git basics:
      • Username (Your name)
      • Email address (This can be fake since we don't actually need it for the lab)
      • Default text editor (Vim)
  4. Challenge

    Install the Gem Required for Using Docker with the Test Kitchen

    Install the gem that Docker requires for this all to work.

  5. Challenge

    Update SELinux to Be Permissive

    1. Run a command to change SELinux so it is permissive.
    2. Open /etc/selinux/config.
    3. Change the SELINUX line from SELINUX=enforcing to SELINUX=permissive.
  6. Challenge

    Create a Cookbook Called la_search Then Move into That Folder

    1. Create a new cookbook called la_search.
    2. Change directory into la_search.
  7. Challenge

    Modify Our Kitchen File

    1. Open kitchen.yml.

    2. In the driver section replace vagrant with docker.

    3. At the bottom of the driver section, add the following (to be in line with the name line):

      privilege: true
      use_sudo: false
      
    4. In the provisioner section, add the following: a name and version as well as a reference to the data_bags location (it should all be in line with the name line):

      product_name: "chef"
      product_version: "13.8.5"
      data_bags_path: /home/cloud_user/chef/data_bags
      
    5. We're on a CentOS machine, so we need to get rid of ubuntu from the file. Delete (or comment out) the line in the platforms section that reads - name: ubuntu-16.04.

  8. Challenge

    Edit Our Recipe

    We need to get the recipe in a state that will do that administrators user installation, if there's not already such a user.

    1. Edit the recipes/default.rb file.

    2. Add these contents below the existing comment lines:

      admins = data_bag('admins')
      
      search(:admins, "gid:administrators").each do |admin|
      
        group admin['gid']
        login = admin["id"]
        admins << login
        home = "/home/#{login}"
      
        user(login) do
          uid admin['uid']
          gid admin['gid']
          shell admin['shell']
          comment admin['comment']
          home home
          manage_home true
        end
      end
      
  9. Challenge

    Build the Kitchen with Our Recipe

    Ensure it all works with kitchen converge. If all goes well, keep going. If not, troubleshoot any typos that may exist.

  10. Challenge

    Test by Logging Into the Kitchen

    1. Log in to the kitchen.
    2. View the contents of /etc/group.
      • We should see an administrators group.
    3. View the contents of /etc/passwd.
      • We should see mike was added in as a user.
  11. Challenge

    Clean up Any Instances That Have Been Created

    1. Log out of the enviroment using exit.
    2. Use kitchen destroy to clean up what we just created.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans