Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Chef Cookbook

You're reading from   Chef Cookbook Achieve powerful IT infrastructure management and automation

Arrow left icon
Product type Paperback
Published in Feb 2017
Publisher Packt
ISBN-13 9781786465351
Length 268 pages
Edition 3rd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
 Marschall Marschall
Author Profile Icon Marschall
Marschall
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Chef Cookbook - Third Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. Chef Infrastructure FREE CHAPTER 2. Evaluating and Troubleshooting Cookbooks and Chef Runs 3. Chef Language and Style 4. Writing Better Cookbooks 5. Working with Files and Packages 6. Users and Applications 7. Servers and Cloud Infrastructure Index

Raising and logging exceptions in recipes


Running your own cookbooks on your nodes might lead to situations where it does not make any sense to continue the current Chef run. If a critical resource is offline or a mandatory configuration value cannot be determined, it is time to bail out.

However, even if things are not that bad, you might want to log certain events while executing your recipes. Chef offers the possibility to write your custom log messages and exit the current run, if you choose to do so.

In this section, you'll learn how to add log statements and stop Chef runs using exceptions.

Getting ready

You need to have at least one cookbook you can modify and run on a node. The following example will use the ntp cookbook.

How to do it...

Let's see how to add our custom log message to a recipe:

  1. Add log statements to the ntp cookbook's default recipe:

    mma@laptop:~/chef-repo $ subl cookbooks/ntp/recipes/default.rb
    Chef::Log.info('** Going to install the ntp service   now...')
    
    service node...
lock icon The rest of the chapter is locked
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 $15.99/month. Cancel anytime
Visually different images