- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud
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.
Lab Info
Table of Contents
-
Challenge
On the Provided Server, Install Version 2.4.17 of the ChefDK Tools
- Download and install the 2.4.17 version of ChefDK at the command line.
- Once it's installed, make sure Chef uses the correct system locations.
- Verify it worked.
-
Challenge
Install What docker-ce Requires on This Server
- Install
yum-utils. - Add the Docker repository.
- Install Docker.
- Set Docker to start now and on system boot.
- Set your user to be able to use Docker without using the
sudocommand. - Log out and back in again
- Check to make sure Docker is running.
- If you can do that without prefacing it with
sudo, you're ready to continue.
- If you can do that without prefacing it with
- Install
-
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.
- Install Git.
- 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)
-
Challenge
Install the Gem Required for Using Docker with the Test Kitchen
Install the gem that Docker requires for this all to work.
-
Challenge
Update SELinux to Be Permissive
- Run a command to change SELinux so it is permissive.
- Open
/etc/selinux/config. - Change the
SELINUXline fromSELINUX=enforcingtoSELINUX=permissive.
-
Challenge
Create a Cookbook Called la_search Then Move into That Folder
- Create a new cookbook called
la_search. - Change directory into
la_search.
- Create a new cookbook called
-
Challenge
Modify Our Kitchen File
-
Open
kitchen.yml. -
In the
driversection replacevagrantwithdocker. -
At the bottom of the
driversection, add the following (to be in line with thenameline):privilege: true use_sudo: false -
In the
provisionersection, add the following: a name and version as well as a reference to thedata_bagslocation (it should all be in line with thenameline):product_name: "chef" product_version: "13.8.5" data_bags_path: /home/cloud_user/chef/data_bags -
We're on a CentOS machine, so we need to get rid of
ubuntufrom the file. Delete (or comment out) the line in theplatformssection that reads- name: ubuntu-16.04.
-
-
Challenge
Edit Our Recipe
We need to get the recipe in a state that will do that
administratorsuser installation, if there's not already such a user.-
Edit the
recipes/default.rbfile. -
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
-
-
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. -
Challenge
Test by Logging Into the Kitchen
- Log in to the kitchen.
- View the contents of
/etc/group.- We should see an
administratorsgroup.
- We should see an
- View the contents of
/etc/passwd.- We should see
mikewas added in as a user.
- We should see
-
Challenge
Clean up Any Instances That Have Been Created
- Log out of the enviroment using
exit. - Use
kitchen destroyto clean up what we just created.
- Log out of the enviroment using
About the author
Real skill practice before real-world application
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.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.