Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Chef Provisioning

You're reading from   Mastering Chef Provisioning Render your entire infrastructure as code with Chef

Arrow left icon
Product type Paperback
Published in Jun 2016
Publisher Packt
ISBN-13 9781785888915
Length 262 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Earl Waud Earl Waud
Author Profile Icon Earl Waud
Earl Waud
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Setting Up a Development Environment on Your Workstation FREE CHAPTER 2. Knife Tooling and Plugins 3. Leveraging Roles, Environments, and Policies 4. Custom Resources 5. Provisioning in the Traditional Data Center 6. Provisioning in the Cloud 7. Test-Driven Development 8. Using Chef Provisioning Index

What is chef-apply?

One often overlooked tool that is installed with the ChefDK is chef-apply. This tool basically allows you to execute chef to converge a single recipe on your local machine. There is no Chef server involved. Everything is local.

Note that chef-apply is not a tool for the deployment of production nodes. It's just a quick and easy way to use Chef to configure your local system.

Why is that useful?

One use case for chef-apply is to learn what a recipe does. You can use chef-apply to run a recipe in a "test only" mode by using the -W or --why-run parameter. This will converge the recipe, showing you everything that would happen with the recipe without making actual changes to your system.

You can also execute some one-liner scripts. You can easily use chef-apply in a scripting-like manner to install software. For example, if you need to use Git on your system and you find it's not installed. Just issue the command:

sudo chef-apply -e "package 'git'"

This will check to see if Git is currently installed. If it is, then the command will just inform you that that is the case and exit. If Git is not installed, then it will go about using the correct installer (aka Provider) to obtain and install the package.

Testing this on my Ubuntu workstation, you can see that Git was not installed initially. Then, by using the chef-apply command, the git package is installed. Then to confirm that nothing happens if you try to use chef-apply to install a package that is already installed, I ran the same chef-apply again to show what happens:

Why is that useful?

How about creating a "workstation" recipe to set up all the "missing" items from a new ChefDK workstations setup? You create the recipe that defines the state of having your editor installed and integrated with Chef, defines the state of having git installed, and defines the state of having your custom OS X "tree" script created in /usr/local/bin. You create this recipe once, and you (and anyone in your organization) can quickly complete their workstation setup by using chef-apply with your workstation recipe.

References

You have been reading a chapter from
Mastering Chef Provisioning
Published in: Jun 2016
Publisher: Packt
ISBN-13: 9781785888915
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image