- Lab
- A Cloud Guru
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.
Path 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
sudo
command. - 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
SELINUX
line fromSELINUX=enforcing
toSELINUX=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
driver
section replacevagrant
withdocker
. -
At the bottom of the
driver
section, add the following (to be in line with thename
line):privilege: true use_sudo: false
-
In the
provisioner
section, add the following: a name and version as well as a reference to thedata_bags
location (it should all be in line with thename
line):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
ubuntu
from the file. Delete (or comment out) the line in theplatforms
section that reads- name: ubuntu-16.04
.
-
-
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.-
Edit the
recipes/default.rb
file. -
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
administrators
group.
- We should see an
- View the contents of
/etc/passwd
.- We should see
mike
was 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 destroy
to clean up what we just created.
- Log out of the enviroment using
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.